2
2

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 1 year has passed since last update.

配列の重複した要素を取り除く(JavaScript)

Posted at

JavaScriptで配列の重複した要素を取り除くサンプルコードです

const array1 = [10,10,40,20,20,30,50,40,70,60,90,70];
// 重複した値を取り除くSetオブジェクトを呼び出す
let array2 = new Set(array1);
// array2を配列に変換し、array3にする
array3 = Array.from(array2);
array3.forEach((data) => {
        document.write(`<p>${data}</p>`);
});

Setオブジェクトに引数としてarray1配列を指定し、Array.from関数で配列に変換します。

2
2
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
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?