This works fine for me:
const iterable = [1, 2, 3];
for (const value of iterable) {
console.log(value);
}
However this does not work:
const iterable = {1:10, 2:20, 3:30};
for (const value of iterable) {
console.log(value);
console.log(iterable[value]);
}
Instead giving me the error:
Uncaught TypeError: iterable[Symbol.iterator] is not a function(…)
How should I be doing this?
This is what I do now:
for(const value in iterable){
if (iterable.hasOwnProperty(value)) {
console.log(value);
console.log(iterable[value]);
}
}