pFad - Phone/Frame/Anonymizer/Declutterfier! Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

URL: http://developer.mozilla.org/pt-BR/docs/Web/JavaScript/Reference/Global_Objects/Map/set

cript>

Esta página foi traduzida do inglês pela comunidade. Saiba mais e junte-se à comunidade MDN Web Docs.

View in English Always switch to English

Map.prototype.set()

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since julho de 2015.

O método set() adiciona ou atualiza um elemento com a chave especificada e um valor do objeto Map.

Experimente

const map1 = new Map();
map1.set("bar", "foo");

console.log(map1.get("bar"));
// Expected output: "foo"

console.log(map1.get("baz"));
// Expected output: undefined

Sintaxe

js
set(key, value);

Parâmetros

key

A chave do elemento que será adicionado ao objeto Map.

value

O valor do elemento que será adicionado ao objeto Map.

Valor retornado

O objeto Map.

Exemplos

Usando o set()

js
let myMap = new Map();

// Adiciona um elemento ao map
myMap.set("bar", "foo");
myMap.set(1, "foobar");

// Atualiza um elemento no map
myMap.set("bar", "baz");

Usando o set de forma encadeada

Já que o método set() retorna o mesmo objeto Map, você pode encadear a chamada do método como abaixo:

js
// Adiciona novos elementos ao map de forma encadeada.
myMap.set("bar", "foo").set(1, "foobar").set(2, "baz");

Especificações

Specification
ECMAScript® 2027 Language Specification
# sec-map.prototype.set

Compatibilidade com navegadores

Veja também

pFad - Phonifier reborn

Pfad - The Proxy pFad © 2024 Your Company Name. All rights reserved.





Check this box to remove all script contents from the fetched content.



Check this box to remove all images from the fetched content.


Check this box to remove all CSS styles from the fetched content.


Check this box to keep images inefficiently compressed and original size.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy