Object【オブジェクト】 の連想配列 | Map【マップ】 | Set 【一意コレクション】 | WeakMap 【弱参照マップ】 | WeakSet 【弱参照一意コレクション】 | |
---|---|---|---|---|---|
コンストラクタ | オブジェクトリテラル new Object ( [ value ] ) | new Map ( [ iterable ] ) | new Set ( [ iterable ] ) | new WeakMap ( [ iterable ] ) | new WeakSet ( [ iterable ] ) |
キー | 文字列・Symbol | 任意 | オブジェクトのみ | ||
値 | 任意 | 任意 | 任意 | 任意 | オブジェクトのみ |
ガベージ手動 | 手動 | 自動 | | ||
要素数 | Object.keys ( obj ).length | size プロパティ | size プロパティ | ||
要素追加・更新 | obj.key obj [ 'key' ] セッター | set ( key, value ) | add ( value ) | set ( key, value ) | add ( value ) |
要素有無 | hasOwnProperty(V) | has ( key ) | has ( value ) | has ( key ) | has ( value ) |
要素値取得 | obj.key obj [ 'key' ] ゲッター | get ( key ) | get ( key ) | ||
要素削除 | delete obj.key delete obj [ 'key' ] | delete ( key ) | delete ( value ) | delete ( key ) | delete ( value ) |
全要素削除 | clear ( ) | clear ( ) | |||
イテレータ オブジェクト作成 (キー・値) | Object.entries(O) (配列取得) | [@@iterator] ( ) entries ( ) | entries ( ) (キー = 値) | ||
イテレータ オブジェクト作成 (キー) | Object.keys( O ) (配列取得) | keys ( ) | keys ( ) (キー = 値) | ||
イテレータ オブジェクト作成 (値) | Object.values(O) (配列取得) | values ( ) | [@@iterator] ( ) values ( ) | ||
反復要素処理 | for-in | for-of forEach (callbackfn [, thisArg]) next() | for-of forEach (callbackfn [, thisArg]) next() |
Set Objects | ||
---|---|---|
ES2022 (13) | ES2021 (12) | ES2020 (11) |
Set.prototype [ @@toStringTag ] | ||
ES2022 (13) | ES2021 (12) | ES2020 (11) |
Set.prototype.constructor | ||
ES2022 (13) | ES2021 (12) | ES2020 (11) |
Set.prototype | ||
ES2022 (13) | ES2021 (12) | ES2020 (11) |
get Set [ @@species ] | ||
ES2022 (13) | ES2021 (12) | ES2020 (11) |
構文 | 説明 |
---|---|
new Set ( [ iterable ] ) | コンストラクタ (new なし:TypeError例外) |
プロパティ | 説明 | |
---|---|---|
Set | [@@species] | コンストラクタ定義 (下記 例を参照) Set[Symbol.species] |
Set.prototype | [@@toStringTag] | タグ (下記 例を参照) [Symbol.toStringTag]:"Set" |
Set.prototype. | constructor | コンストラクタ定義 (下記 例を参照) |
Set. | prototype | プロトタイプ (下記 例を参照) |
Set.prototype. | size | 要素数 |
メソッド | 説明 | 備考 | |
---|---|---|---|
Set.prototype | [@@iterator] () | イテレータオブジェクト作成 [Symbol.iterator] () | キー = 値 |
Set.prototype. | add ( value ) | 要素追加・更新 | |
Set.prototype. | clear ( ) | 全要素削除 | |
Set.prototype. | delete ( value ) | 要素削除 | |
Set.prototype. | entries ( ) | イテレータオブジェクト作成 | キー = 値 |
Set.prototype. | forEach ( callbackfn [, thisArg] ) | 反復要素処理 | |
Set.prototype. | has ( value ) | 要素有無 | |
Set.prototype. | keys ( ) | イテレータオブジェクト作成 (キー) | キー = 値 |
Set.prototype. | values ( ) | イテレータオブジェクト作成 (値) |
console.log(Set.prototype.constructor);
// 出力:function Set() { [native code] }
console.log(Set.prototype);
// 出力:
// Set
// add: function add()
// clear: function clear()
// constructor: function Set()
// delete: function delete()
// entries: function entries()
// forEach: function forEach()
// has: function has()
// keys: function values()
// size: (...)
// get size: function size()
// values: function values()
// Symbol(Symbol.iterator): function values()
// Symbol(Symbol.toStringTag): "Set"
// __proto__: Object
console.log(Set[Symbol.species]);
// 出力:function Set() { [native code] }
var set1 = new Set();
console.log(set1[Symbol.toStringTag]);
// 出力:Set
console.log(set1.constructor);
// 出力:function Set() { [native code] }
set1.add(1);
set1.add("string2");
var obj3 = new Object("obj3");
set1.add(obj3);
console.log(set1.has(1)); // 出力:true
console.log(set1.has("string2")); // 出力:true
console.log(set1.has(obj3)); // 出力:true
console.log(set1.size); // 出力:3