by _bxg1 · 7y ago · 0 comments
array.filter((item, index, arr) => arr.indexOf(item) === index)
It works because indexOf returns the index of the first occurrence of the item, so you're asking whether this occurrence is the first occurrence. const unique = [...new Set(arr)];The one I posted just blew my mind a little the first time I saw it, so I love to share it. I guess I never really considered spreading a set.
array.filter(Boolean)I try not to leave grenades laying around too often, myself.