JavaScriptIntermediate#es6#collections

Difference between Map/Set and plain objects/arrays?

Map allows any key type, keeps insertion order and exposes size with O(1) add/delete. Set stores unique values and makes deduplication trivial, whereas objects coerce keys to strings and arrays need O(n) lookups.

Example
const s = new Set([1,1,2]);   // {1,2}
[...new Set(arr)];            // dedupe
const m = new Map();
m.set({id:1}, 'obj key');

Related Questions

1
JavaScriptIntermediate#objects

What is the difference between shallow copy and deep copy?

Open
2
JavaScriptBeginner#es6#strings

What are template literals?

Open
3
JavaScriptAdvanced#functions

What is currying?

Open