let collection = [{
name: 'music',
views: 20
},
{
name: 'abc',
views: 32
},
{
name: 'bob',
views: 20
}
]
for (const [k, v] of collection) {
console.log(k, v)
}
console.log(Array.isArray(collection))
Error: .for is not iterable
Array.isArray(collection)
returns true
How can an array not be iterable?
Do I really need to resort to this to "get" the index of each item?
for (let i = 0; i < collection.length; i++){
console.log(i, collection[i])
}
nvm ...it works fine with forEach
collection.forEach((k, v) => {
console.log(k,v)
})
What's going with for...of here?
Note: I can't use for...in b/c i need the order to be guaranteed