[js] 배열에서 중복 제거

September 13, 2018

filter 와 indexOf 를 이용한 중복제거 방법

var a = ["a", 1, "a", 2, "1"]
var unique = a.filter((v, i, s) => s.indexOf(v) === i) // returns ['a', 1, 2, '1']

Ref

https://stackoverflow.com/questions/1960473/get-all-unique-values-in-a-javascript-array-remove-duplicates


Profile picture

Written by min9nim - About Email GitHub
who writes practical code and builds useful things.