Skip to content

re: Looping through objects in JavaScript VIEW POST


Zell Liew, just wanted to add my 2cents to this well written article.

I feel if one realises that a particular object would require a lot of iteration then maybe they need to start thinking about ditching the object in favour of data structures which have a first party support for iteration.

With ES6 we have a new fancy data structure called Map and it is a perfect fit for those cases where you are overloading an object with thousands of properties and also want to iterate through them.

A simple example of Map.

var map = new Map();

map.set('random', 34);
map.set('abc', 42);

for(const val of map.values()) {

MDN Docs for Map

code of conduct - report abuse