This is the problem -
" We have defined a function, filteredArray
, which takes arr
, a nested array, and elem
as arguments, and returns a new array. elem
represents an element that may or may not be present on one or more of the arrays nested within arr
. Modify the function, using a for
loop, to return a filtered version of the passed array such that any array nested within arr
containing elem
has been removed. "
This is my code -
function filteredArray(arr, elem) {
let newArr = [];
// Only change code below this line
for(let i=0; i<arr.length;i++)
{
if(arr[i].indexOf(elem)!=-1)
{
arr.splice(i,1);
}
}
newArr=[...arr];
// Only change code above this line
return newArr;
}
console.log(filteredArray([[3, 2, 3], [3, 13, 26], [1, 6, 3], [19, 3, 9]], 3));
**Your browser information:**
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.159 Safari/537.36
Challenge: Iterate Through All an Array’s Items Using For Loops
Link to the challenge: