Content-Length: 190969 | pFad | http://developer.mozilla.org/ru/docs/Web/JavaScript/Reference/Global_Objects/Set/add

Set.prototype.add() - JavaScript | MDN

This page was translated from English by the community. Learn more and join the MDN Web Docs community.

View in English Always switch to English

Set.prototype.add()

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since июль 2015 г..

Метод add() добавляет новый элемент с заданным значением в конец объекта Set.

Интерактивный пример

const set1 = new Set();

set1.add(42);
set1.add(42);
set1.add(13);

for (const item of set1) {
  console.log(item);
  // Expected output: 42
  // Expected output: 13
}

Синтаксис

mySet.add(value);

Параметры

value

Обязательное. Значение элемента, добавляемого в объект Set.

Возвращаемое значение

Объект Set.

Примеры

Использование метода add

js
var mySet = new Set();

mySet.add(1);
mySet.add(5).add("some text"); // можно делать цепочки

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

Спецификации

Specification
ECMAScript® 2026 Language Specification
# sec-set.prototype.add

Совместимость с браузерами

Смотрите также









ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


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

Fetched URL: http://developer.mozilla.org/ru/docs/Web/JavaScript/Reference/Global_Objects/Set/add

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy