-3

suppose, I have array let arr = [0,1,[2],3,4]

i want to remove [2] from arr array by only value [2].

expected array would be arr = [0,1,3,4]

i appreciate your help, thank you.

1 Answers1

0

This should help!

let arr = [0, 1, [2], 3, 4, 'A', [2], { name: 'John' }];

const match = (a1, a2) => {
  if (a1.length !== a2.length) return false;
  for (let i = 0; i < a1.length; i++) {
    if (a1[i] !== a2[i]) return false;
  }
  return true;
};

const target = [2];
arr = arr.filter((el) => !match(el, target));

console.log(arr);
Som Shekhar Mukherjee
  • 4,701
  • 1
  • 12
  • 28