31
22

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

[JavaScript] スプレッド演算子で配列の重複を削除する

Last updated at Posted at 2021-03-28

#概要
jsでスプレッド演算子を活用して、配列の重複している部分を削除する際のメモです。

#実装

.js
const array1 = [1, 2, 2, 1, 3, 4, 4];
const array2 = [...(new Set(array1))];
console.log(array2);

//結果:[1,2,3,4]

Setオブジェクトは重複した値がないことを保証するので、このような記述で重複しない配列を作成することができます。

31
22
2

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
31
22

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?