Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove duplicate arrays in an array? [closed]

Tags:

javascript

const arr = [[1, 2], [1, 2], [3, 4], [7, 7]];

how to remove duplicate arrays from the given array? The first two elements of the array are the same. I couldn't fix it with the set.

like image 553
Jibin John Avatar asked Oct 16 '25 16:10

Jibin John


1 Answers

Use method filter().

const arr = [[1, 2], [1, 2], [3, 4], [7, 7]];
const arrNoDouble = arr.filter((a = {}, b => !(a[b] = b in a)));

console.log(JSON.stringify(arrNoDouble));
like image 55
s.kuznetsov Avatar answered Oct 18 '25 07:10

s.kuznetsov