I have array like this below
[[0,0,1],
[0,0,3]
[0,0,3]//duplicate
[0,1,3]
[1,0,0]
[1,2,1]
[1,2,1]//duplicate
[2,2,2]]
I want to make array like this below,
[[0,0,1],
[0,0,3]
[0,1,3]
[1,0,0]
[1,2,1]
[2,2,2]]
At first, I tried with this, but it returns []
myarray = myarray.filter(
(element,index,self) =>self.findIndex((e) => {
e[0] == element[0] &&
e[1] == element[1] &&
e[2] == element[2]
}) === index
)
How can I make this work?
2
Answers
I use
.toString()
on each array, remove duplicated strings then split them again.A safe method is to combine Set with JSON.stringify and .parse