LoginSignup
2
0

More than 3 years have passed since last update.

【JavaScript】Mapの値を配列に変換する

Last updated at Posted at 2020-09-22

はじめに

Mapで格納した値のvaluesのみを抽出して配列に変換したい時に使えるTipsです。

一般的な方法

index.js
const sampleMap = new Map();
sampleMap.set(1, 'a');
sampleMap.set(2, 'b');
const values = Array.from(sampleMap.values());
// ["a", "b"]

スプレッド演算子を用いた方法

index.js
const sampleMap = new Map();
sampleMap.set(1, 'a');
sampleMap.set(2, 'b');
const values =[...sampleMap.values()];
// ["a", "b"]
2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0