1
0

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 5 years have passed since last update.

重複を取り除いた配列を作りたいとき[Javascript]

Posted at

Setに変換してしまうと簡単です。
そのまま for..of で値を取り出すこともできるし、配列に戻したければスプレッド演算子を組み合わせます。

let test = [1,2,2,3,4,4,6]
let set1 = new Set(test)

for (let v of set1) {
  console.log(v) // 1, 2, 3, 4, 6
}

let arr1 = [...set1]
console.log(arr1) // [1,2,3,4,6]

Setオブジェクト

1
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
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?