JavaScript: Map.prototype.set

By Xah Lee. Date: . Last updated: .

New in ES2015.

Map.prototype.set(key, val)

Add a entry to the map. If the key already exist, overwrite its value.

Returns the modified map.

// create a map, add entry to it
var m = new Map();
m.set (3, "n3");

// the map is modified
console.log(m) // Map { 3 => 'n3' }

console.log( m.set (4, "n4")); // Map { 3 => 'n3', 4 => 'n4' }
// “set” returns the modified map


ECMAScript 2015 §Keyed Collection#sec-map.prototype.set

Map Topic

  1. JavaScript: the Map Object Tutorial
  2. JavaScript: Map Object
  3. JavaScript: Map.prototype
  4. JavaScript: Iterate Over Map Object
  5. JavaScript: Convert Object to/from Map
Like what you read? Buy JavaScript in Depth
or, buy a new keyboard, see Keyboard Reviews.