I don't know why why I'am getting this error :
TypeError: Cannot read property 'length' of undefined
I have defined e to 0 in the 1st loop. So what's the deal ?
function filteredArray(arr, elem)
{
let newArr = [];
for(let e = 0; e < arr.length; e++)
{
for ( let j = 0; j < arr[e].length; j++)
{
if(arr[e][j] == elem)
{
arr.splice(e, 1);
}
}
newArr = arr;
}
return (newArr);
}
EDIT : To give more context , I'am trying to remove an array from array of arrays if it contains the elem. Like :
filteredArray([[10, 8, 3], [14, 6, 23], [3, 18, 6]], 18) should return [[10, 8, 3], [14, 6, 23]]
filteredArray([["trumpets", 2], ["flutes", 4], ["saxophones", 2]], 2) should return [["flutes", 4]]
filteredArray([["amy", "beth", "sam"], ["dave", "sean", "peter"]], "peter") should return [["amy", "beth", "sam"]]
filteredArray([[3, 2, 3], [1, 6, 3], [3, 13, 26], [19, 3, 9]], 3) should return []