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.
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.
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);