どうも、ちょげ(@chogetarou)です。
Mapの連想配列の全てのキー(key)を取得する方法を紹介します。
方法

Mapの連想配列の全てのキー(key)を取得するには、keys()を使います。
具体的には、map.keys
()のように、Mapの連想配列からkeys()を呼び出します。
const keys = map.keys();
上記のkeys()は、呼び出したMapの連想配列の全てのキーをイテレーターとして取得します。
使用例
const numbers = new Map([[ "one", 1], ["two", 2], ["three", 3], ["four", 4], ["five", 5 ]]);
const keys = numbers.keys();
console.log(keys);
出力:
[Map Iterator] { 'one', 'two', 'three', 'four', 'five' }
コメント