--- title: Map.prototype.set() slug: Web/JavaScript/Reference/Global_Objects/Map/set tags: - ECMAScript6 - JavaScript - Mapa - Prototype - metodo translation_of: Web/JavaScript/Reference/Global_Objects/Map/set original_slug: Web/JavaScript/Referencia/Objetos_globales/Map/set ---
El método set() agrega un nuevo elemento al objeto Map con la llave y el valor especificado.
myMap.set(llave, valor);
El objeto Map.
var miMapa = new Map();
// Agregar nuevos elementos al mapa
miMapa.set("bar", "foo");
miMapa.set(1, "foobar");
// Actualizar un elemento en el mapa
miMapa.set("bar", "baz");
| Specification | Status | Comment |
|---|---|---|
| {{SpecName('ES6', '#sec-map.prototype.set', 'Map.prototype.set')}} | {{Spec2('ES6')}} | Initial definition. |
| {{SpecName('ESDraft', '#sec-map.prototype.set', 'Map.prototype.set')}} | {{Spec2('ESDraft')}} |
{{CompatibilityTable}}
| Caracterítica | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari |
|---|---|---|---|---|---|
| Soporte Básico | 38 | {{CompatGeckoDesktop("13.0")}} | 11 | 25 | 7.1 |
| Caracterítica | Android | Chrome para Android | Firefox Mobile (Gecko) | IE Mobile | Opera Mobile | Safari Mobile |
|---|---|---|---|---|---|---|
| Soporte Básico | {{CompatNo}} | 38 | {{CompatGeckoMobile("13.0")}} | {{CompatNo}} | {{CompatNo}} | 8 |
Map.prototype.set retorna undefined y no es encadenable. Esto se ha reparado ({{bug(1031632)}}). Este comportamiento también se encontró en Chrome/v8 (issue).