Understand for...in and for...of in two sentences

for...of traverses to obtain the key value of the object, for...in obtains the key name of the object;
for...in traverses the entire prototype chain of the object, the performance is very poor and is not recommended, and for. ..of only traverses the current object and does not traverse the prototype chain;
for array traversal, for...in returns all enumerable properties in the array (including enumerable properties on the prototype chain), for...of Only return the attribute value corresponding to the subscript of the array;

Summary: The for...in loop is mainly for traversing objects, not for traversing arrays; the for...of loop can be used for traversing arrays, array-like objects, strings, Sets, Maps, and Generator objects

Guess you like

Origin blog.csdn.net/qq_53114797/article/details/130339838