for - in

Added in ES 2015.
This should not be used to iterate over an Array where the index order is important.
The order in which the items are accessed is not guaranteed to be in sequential order.
When the order is important you should use a for loop, a for of loop, or Array.forEach() when the order is important.

const numbers = [10, 20, 30, 40, 50]; 
let result = "";
for (let x in numbers) {
  result += numbers[x] + " ";
}
console.log(result) = 10 20 30 40 50



var people = ["steve","john","people"]; 
for (i in people) {
   alert(people[i]);
}



All the Characters

let str = "BetterSolutions" 

for (const char in str) {
 console.log(char + " = " + str[char]);
}



© 2022 Better Solutions Limited. All Rights Reserved. © 2022 Better Solutions Limited TopPrevNext