need help with For loop array , i want the opposite data of function,
but when i try arr[i] != elem it print out all the array;
and if i try arr[i] == elem , it give me the array that i don't want;
still don't understand why it not work with != (not equal).
function filteredArray(arr, elem) {
let newArr = [];
// change code below this line
for(let i = arr.length -1; i >= 0 ; i--) {
for(let j = arr[i].length-1;j >= 0;j--) {
if(arr[i][j] !== elem) {
newArr.push(arr[i]);
}
}
}
// change code above this line
return newArr;
}
console.log(filteredArray([ ["trumpets", 2], ["flutes", 4], ["saxophones", 2] ], 2));
the result i want is ["flutes", 4]
sorry if this have been asking by others, i have been looking for the answer trough google , but can not find it.
thanks for the help