I can't delete an array nested inside another array

I feel like I am a step away from getting it right
the console tells me that there is something wrong with arr.length

function filteredArray(arr, elem) {
let newArr = ;
// Only change code below this line
for (let i = 0; i < arr.length; i++) {
for (let j = 0; j < arr[i].length; j++) {
if (arr[i][j] === elem) {
console.log(arr.splice(arr[i], arr.length));
newArr = arr;
}
}
}
// Only change code above this line
return newArr;
}
filteredArray(
[
[3, 2, 3],
[1, 6, 3],
[3, 13, 26],
[19, 3, 9],
],
3
);

Welcome to the forum

It looks like your code is mutating the original array. Is this what you want?

1 Like

Yes I want to delete any nested array that contains number 3
It is a challenge here on the javascript course

If you want to change the original array, why do you need to return newArr?

What challenge is this for, and are you supposed to change the source array?

I am still learning. I thought this is the answer to the question…how am i supposed to fix this to answer the question

Without knowing which challenge this is for, here are some guesses.

  • The challenge may not want you to alter the original array.

  • You have to return newArray, which doesn’t contain a certain element.

  • The source array is nested, so you need a way to iterate though the array.

  • You have to check for a certain element - write down the different ways to do this.

  • What are the alternatives to deleting items?

We cannot give solutions on the forum.
I’ve spent days working on a single problem, the pay off is that I learn a lot more, and the next challenging problem is a little easier.

If you want, try out some different ways to approach the problem. If you get stuck, just ask the forum for help.

3 Likes

Thanks a lot for your help👍

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.