JS: 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

Reference

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

Map Topic

  1. JS: the Map Object Tutorial
  2. JS: Map Object
  3. JS: Map.prototype
  4. JS: Iterate Over Map Object
  5. JS: Convert Object to/from Map
Like what you read? Buy JavaScript in Depth