--- title: Set.prototype.add() slug: Web/JavaScript/Reference/Global_Objects/Set/add tags: - ECMAScript 2015 - JavaScript - Method - Prototype - Reference - set translation_of: Web/JavaScript/Reference/Global_Objects/Set/add ---
{{JSRef}}

add() メソッドは、特定の value をもつ新しい要素を Set オブジェクトの最後に追加します。

{{EmbedInteractiveExample("pages/js/set-prototype-add.html")}}

構文

mySet.add(value);

引数

value
Set オブジェクトに追加する要素の値です。

返値

Set オブジェクトです。

add() メソッドの使用

var mySet = new Set();

mySet.add(1);
mySet.add(5).add('some text'); // メソッドチェーン

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

仕様書

仕様書
{{SpecName('ESDraft', '#sec-set.prototype.add', 'Set.prototype.add')}}

ブラウザーの互換性

{{Compat("javascript.builtins.Set.add")}}

関連情報