1.

What is the difference between for..of and for..in?

Answer»
  • for in: runs over an object's ENUMERABLE property names.
  • for of: (new in ES6) takes an object-specific ITERATOR and loops through the data it generates.

Both the for..of and for..in commands ITERATE over lists, but the RESULTS they return are different: for..in returns a list of keys on the object being iterated, whereas for..of returns a list of values of the object's numeric attributes.

let arr = [3, 4, 5];for (let i in arr) { console.log(i); // "0", "1", "2",}for (let i of arr) { console.log(i); // "3", "4", "5"}


Discussion

No Comment Found