DEV Community

Discussion on: Problems with Using for...in on Arrays in JavaScript

Collapse
 
srikanth74659 profile image
Srikanth

It's informative and straight to point..
Also if possible can you change examples for "What is for...in?" as

array = [4, "some text", true];

for (let i in array) {  //  in for..in 'i' returns index
  console.log(i); // 0, 1, 2
  console.log(typeof i); // string, string, string
  console.log(array[i]); // 4, some text, true
}

for (const el of array) {   //  in for..of 'el' returns element
  console.log(el);  // 4, some text, true
  console.log(typeof el);   // number, string, boolean
}

Anyways..thanks for the information

Collapse
 
imjoshellis profile image
Josh Ellis

Thanks for the extra info!