Next gripe about javascript.

The idiomatic way to create an array is

let something = [];

The idiomatic way to create an object is

let otherthing = {};

The idiomatic way to create a set

let myset = new Set();

The idiomatic way to create a map

let mymap = new Map();

AND
if you want to actually loop through the data in an object {}, you have to beware of prototype data that you never put in there, so you write

Object.entries(obj).forEach(([k,v]) => …)

or old school

for (const key in obj) {
if (Object.prototype.hasOwnProperty.call(obj, key)) {
console.log(key, obj[key]);
}
}

#programming #javascript

@randomwizard Or use #UnderscoreJS, where most functions work the same regardless of whether you iterate over an array or an object.

(Map and Set nog supported yet, but planned for version 2.)

@randomwizard for-of loops don't require you to check the prototype and are the better default "iterate over items in a collection" mechanism IMHO.