Array iteration methods
Arrays have a rich set of iteration methods:
const nums = [1, 2, 3];
nums.forEach(n => console.log(n)); // run side effects
nums.map(n => n * 2); // transform
nums.filter(n => n > 1); // subset
nums.find(n => n > 1); // first match
nums.some(n => n > 2); // any match
nums.every(n => n > 0); // all match
forEach returns nothing and is for side effects; map/filter/reduce return new arrays/values and compose well.
Objects under the hood
An object is a map of string keys to values. Modern engines optimize objects used as data containers. Use arrays for ordered, numeric-indexed collections and objects for keyed lookup:
const map = new Map();
map.set(1, "one"); // keys can be anything
map.get(1); // 'one'
const set = new Set([1, 1, 2]); // unique only: Set {1, 2}
Map and Set (ES2015) give unique collections and any-key maps, which are faster for large dynamic data than plain objects.