DEV Community

Discussion on: How to iterate through objects in JAVASCRIPT ?

Collapse
 
jenbutondevto profile image
Jen

Nice - I'd never implemented iterator by hand before. I'd say Object.entries|values|keys is more effective in terms of loc. Is there any reason why you'd use iterator over the Object methods?

const range = { a: 1, b: 2, c: 5, d: 8 }
console.log(...Object.values(range))
// 1 2 5 8
Enter fullscreen mode Exit fullscreen mode

With .entries you get access to your keys too.

console.log(...Object.values(range))
// [ 'a', 1 ] [ 'b', 2 ] [ 'c', 5 ] [ 'd', 8 ]
Enter fullscreen mode Exit fullscreen mode
Collapse
 
hssanbzlm profile image
Hssan Bouzlima

This quick article is just to show the source of "TypeError: Found non-callable @@iterator" error and why we can't use for..of loop and spread operator with objects