let arr = [{
category: 'music',
views: 20
},
{
category: 'abc',
views: 32
},
{
category: 'bob',
views: 20
}
]
for (const [key, value] of arr) {
console.log(key, value)
}
console.log(Array.isArray(arr))
Error: .for is not iterable
Array.isArray(arr)
returns true
Why is the array not iterable?
Is it necessary to use this method to retrieve the index of each item?
for (let i = 0; i < arr.length; i++){
console.log(i, arr[i])
}
Nevermind ...it works well with forEach
arr.forEach((key, value) => {
console.log(key,value)
})
What's happening with for...of here?
Note: Using for...in is not an option because the order needs to be guaranteed