js for item in array code example
Example 1: es6 forEach
const array1 = ['a', 'b', 'c'];
array1.forEach((element) => {
console.log(element)
});
Example 2: javascript object array iteration
let obj = {
key1: "value1",
key2: "value2",
key3: "value3"
}
Object.keys(obj).forEach(key => {
let value = obj[key];
});
Example 3: javascript foreach index
users.forEach((user, index)=>{
console.log(index);
});
Example 4: js for each item do
let array = ['Item 1', 'Item 2', 'Item 3'];
array.forEach(item => {
console.log(item);
});
Example 5: for in javascript
for (let i = start; i < end; i++) {
}
Example 6: javascript iterate array
String[] myStringArray = {"Hello", "World"};
for (String s : myStringArray)
{
}