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

重複削除、配列内、配列内オブジェクト両方。

0
Last updated at Posted at 2019-06-05

-配列内の要素とキーを使った配列内オブジェクトに対する重複削除。
demo https://codepen.io/gnjo/pen/vwMROz

let fn={};
fn.setary=(ary,key)=>{
 return (!key)?Array.from(new Set(ary)):ary.filter((a,b,c)=>(c.findIndex((d)=>(a[key]===d[key]))=== b))
}
;
let a=[1,2,3,4,5,6,7,8,9,1,2,3,4,5,6,7,8,9]
let aa=fn.setary(a) 
console.log(aa)//[1,2,3,4,5,6,7,8,9]
;
let b=[{key:1,value:1},{key:2,value:1},{key:3,value:1},{key:1,value:1},{key:2,value:1}]
let bb=fn.setary(b,'key')
console.log(bb)//[{key:1,value:1},{key:2,value:1},{key:3,value:1}]
;
0
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
0
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?