eliminate duplicates from multidimensional arrays js

  • The input array (arr1, arr2) are multi-dimensional arrays so it is needed to make them to 1d array using Array.prototype.flat() function.

  • After making it to 1d array, you can get the unduplicated members using Array.prototype.filter function. (To check if the arr2 includes the item or not, you can use Array.prototype.includes function.).

const arr1 = [ ['11:00','12:00','13:00'] ];
const arr2 = [ ['11:00'],['13:00'] ];

const arr1Flat = arr1.flat();
const arr2Flat = arr2.flat();

const output = arr1Flat.filter((item) => !arr2Flat.includes(item));

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top