--- title: Set.prototype.add() slug: Web/JavaScript/Reference/Global_Objects/Set/add translation_of: Web/JavaScript/Reference/Global_Objects/Set/add original_slug: Web/JavaScript/Referencia/Objetos_globales/Set/add ---
{{JSRef}}

El método add() añade un nuevo elemento con un valor específico al final del objeto Set.

Sintaxis

mySet.add(value);

Parameters

value
Requerido. El valor del elemento a ser añadido al objeto Set.

Return value

El objeto Set.

Ejemplos

Usando el método add

var mySet = new Set();

mySet.add(1);
mySet.add(5).add("some text"); // chainable

console.log(mySet);
// Set [1, 5, "some text"]

Specifications

Specification Status Comment
{{SpecName('ES6', '#sec-set.prototype.add', 'Set.prototype.add')}} {{Spec2('ES6')}} Initial definition.
{{SpecName('ESDraft', '#sec-set.prototype.add', 'Set.prototype.add')}} {{Spec2('ESDraft')}}  

Browser compatibility

{{CompatibilityTable}}

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari
Basic support 38 {{CompatGeckoDesktop("13.0")}} 11 25 7.1
Feature Android Chrome for Android Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile
Basic support {{CompatNo}} 38 {{CompatGeckoMobile("13.0")}} {{CompatNo}} {{CompatNo}} 8

Firefox-specific notes

See also