Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

js array for in vs for of

let arr = ['el1', 'el2', 'el3'];

arr.addedProp = 'arrProp';

// elKey are the property keys
// (equivalent to an index for an array)
for (let elKey in arr) {
  console.log(elKey); // Will print: 0, 1, 2, addedProp
}

// elValue are the property values
for (let elValue of arr) {
  console.log(elValue) // Will print: el1, el2, el3
}
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #js #array
ADD COMMENT
Topic
Name
1+2 =