How should web front-end traversal objects operate?

In the last issue, we talked about the way the front-end traverses the array, but we sometimes encounter situations where we need to traverse the object, so how should we traverse the object? Xiaoqian will tell you today.

One, for....in to traverse objects

Generally used to traverse the object keys representing the key of each key-value pair of the obj object

1.jpg

Output result:

2.png

2. For...in to traverse the array (not recommended)

3.png

Output result:

4.png

for...in reads the attribute name in a loop, and then obtains the attribute value through the attribute name

The for...in loop is mainly designed for traversing objects. Although it can traverse arrays, it is not recommended to use it in this way.

This article is from Qianfeng Education , please indicate the source for reprinting.

Guess you like

Origin blog.51cto.com/15128702/2676144