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, to traverse objects

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


Output result:


2. to traverse the array (not recommended)


Output result:

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

The 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