How to remove duplicate subarrays from a multi-dimensional array in Node.js

1 Answer

0 votes
const array = [
    ["abc", "def"],
    ["ghi", "jkl"],
    ["mno", "ppp"],
    ["abc", "def"],
    ["ghi", "jkl"],
    ["mno", "ppp"]
];

// Function to remove duplicate subarrays
function arrayUnique(arr) {
    const uniqueSet = new Set(arr.map(subArray => JSON.stringify(subArray)));
    
    return Array.from(uniqueSet).map(subArray => JSON.parse(subArray));
}

const uniqueArray = arrayUnique(array);

console.log(uniqueArray);



/*
run:

[ [ 'abc', 'def' ], [ 'ghi', 'jkl' ], [ 'mno', 'ppp' ] ]

*/

 



answered Apr 7 by avibootz
...