I have a multidimensional array like this:
let arr = [ [1,2,3], [3,4,6], [4,5,7], [8,9,3]];
and I need to use only a filter function for filtering this array. I must filter the array and create a new array from the current inner arrays which contain the number 3:
let myArr = [ [1,2,3], [3,4,6], [4,5,7], [8,9,3]];
function getVal(value, arr){
for(let i in arr){
for(let j in arr[i]){
if(arr[i][j] == value){
return true;
}
}
}
}
let newArr = myArr.filter(getVal(3, myArr));
My code is not working. Actually, it's working, but I don`t see any result.
The expected result is like this:
newArr = [[1,2,3], [3,4,6], [8,9,3]];
All I have found are filter methods with objects.