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
Output result:
2. For...in to traverse the array (not recommended)
Output result:
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.