I believe everyone has used a For loop in JavaScript, which is mainly used to iterate over the array objects, and it is easy to perform repetitive operations and reflect the reusability of the code. However, the index of an array should generally be a number of integers, and when a JSON object or object is encountered, it cannot be traversed with a for loop, and the object should be traversed with the for in function, where the individual's understanding of for IS.
First of all, even though the keyword is called for-in syntax, the syntax can also be used to traverse the object, get the object's property name, and then get the object by the object name [property name]. Personally, the key to understanding the nature of this grammar is to understand what each cycle gets.
The implementation of the for in feature is extended from the for loop because the array index of JavaScript can be a string. Here's an example,
After clicking the button one:
0:blue
1:red
2:yellow. Click button after: uname: Zhang San
Age:18 This is the result of the above code output, you can also imagine if there is a method in U1 u1.say=function () {
Alert ("Hello");
}, then click on the output uname: Zhang San
Age:18
Say:function () {alert ("Hello");} Therefore, you can iterate through the JSON object and the Obj object using for in! Purely personal experience, the wrong place, please advise!On the in syntax of JavaScript