Basic Data Structures - Remove Items Using splice()

Tell us what’s happening:

Weirdest thing is happening. When I’m logging the result of arr, it’s completely ignoring splice…

 arr.splice(1,3)
// logs [2,1] - the last two elements.

When I use the same code and assign the value to a new variable I get the correct result.

 let newArr = arr.splice(1,3)
// logs [4,5,1]

Is this an extension issue, have others seen this before?

Note regardles of whether I delete the line let newArr, I still do not get the correct result in arr…

Your code so far

const arr = [2, 4, 5, 1, 7, 5, 2, 1];
// Only change code below this line
let newArr = arr.splice(1,3)
arr.splice(1,3)
// Only change code above this line
console.log(arr);
console.log(newArr)


/*
.splice(index, numberOfItemsToDelete)
*/

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.0.0 Safari/537.36

Challenge: Basic Data Structures - Remove Items Using splice()

Link to the challenge:

The splice is not being ignored at all. You are removing elements at index 1, 2, and 3

image
what do you mean that soluce is being ignored?
it’s not

image

It must be a local issue… I’m sure the code splice(1,3) is correct?

Your screenshot shows that you removed the elements 4, 5, 1 from arr.

splice(1, 3) does not meet the requirements of the assignment, no. You are removing three elements, but the remaining elements do not sum to 10.

1 Like

it’s doing what you wrote, it has removed three elements starting at index 1

notice, that the 4 5 and 1 are not there anymore

1 Like

Okay, I see… Apologies for the confusion. I understand now!

Thank you @ilenia and @JeremyLT for your help!

1 Like