Error in Remove Items Using splice()

Tell us what’s happening:
Describe your issue in detail here.

Hello, I noticed an error with the result of the example code.
The result of the example code given should be “I am feeling” and not “really happy”.
Thank you
Your code so far

let array = ['I', 'am', 'feeling', 'really', 'happy'];

let newArray = array.splice(3, 2);

console.log(array); // I am feeling, not really happy
  **Your browser information:**

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

Challenge: Remove Items Using splice()

Link to the challenge:

The example code is showing the contents of newArray, not the original array.

let array = ['I', 'am', 'feeling', 'really', 'happy'];
let newArray = array.splice(3, 2);
console.log(newArray)

produces

[ 'really', 'happy' ]

1 Like

splice function works like this:
array.splice(index, how many, item1, …, itemX);

Which means that your index is starting at position 3 in your array.

Good documentation of this function can be found here:

1 Like

Oh, I mixed up things there. I totally understand now. Thank you