Input:
[[-1,-1,2],[-1,0,1],[-1,-1,2],[-1,0,1],[-1,-1,2],[-1,0,1],[-1,0,1]]
The output I want:
[[-1,-1,2],[-1,0,1]]
Any other ideas except this one?
Thanks
You won't really get around stringifying the arrays, as that's the simplest (and reasonably fast) way to compare them by value. So I'd go for
Array.from(new Set(input.map(JSON.stringify)), JSON.parse)
See also Remove Duplicates from JavaScript Array for other approaches, though most of them will require two values to be comparable by ===.
===
2.1m questions
2.1m answers
60 comments
57.0k users