6
8

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.

2次元配列中の重複削除

Last updated at Posted at 2019-09-20

Google Spreadsheet使ってると2次元配列中の複数の要素にまたがった重複削除とかやりたくなると思いますが,こうすると行数短く書けるなぁと思いついたのでメモ.

remove_duplicated.js
const A = [["田中", "裕也"], ["田中", "智史"], ["吉田", "智史"], ["田中", "智史"]];

const unique_A = A.filter(function(e, index){
  return !A.some(function(e2, index2){
    return index > index2 && e[0] == e2[0] && e[1] == e2[1];
  });
});

Logger.log(unique_A); // 田中,裕也,田中,智史,吉田,智史

配列から重複削除するには他にSetやreduce使う方法があるらしいけど,そっちはまだ試してない.

6
8
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
6
8

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?