array javascript loop code example
Example 1: loop through an array javascript
let array = ['Item 1', 'Item 2', 'Item 3'];
for (let index = 0; index < array.length; index++) {
console.log(array[index]);
}
for (let index in array) {
console.log(array[index]);
}
for (let value of array) {
console.log(value);
}
array.forEach((value, index) => {
console.log(index);
console.log(value);
});
Example 2: javascript loop array
var data = {
name: "root",
contents: [
{
name: "A",
contents: [
{
name: "fileA1",
contents: ["Hello!"]
}
]
},
{
name: "B",
contents: [
{
name: "dirB1",
contents: [
{
name: "fileB1.1",
contents: ["Hello!"]
}
]
}
]
}
]
};
Example 3: ex: javascript loop array
<a href="#" title="Header" data-toggle="popover" data-trigger="hover" data-content="Some content">Hover over me</a>