0

Why does the new array only contain the value '394', instead of all the other ones?

const values = [5, 11, 394, 2, 576];  

function pureSplice(givenArray: number[]){  
    const newArray: number[] = givenArray.splice(2, 1).map(x => x);  
    return newArray;  
}

pureSplice(values);

The 'newArray' only contains the value '394', why does it do that and is there a way to get the array to have all values other than 394' with .splice and .map?

Partande
  • 1
  • 2
  • [Check this](https://stackoverflow.com/questions/31202768/get-array-without-element-at-index). I think it solves your problem. – jgcarrillo Jan 30 '23 at 13:00
  • `splice` returns an array of the removed items, not a reference to the updated array. Also note that it modifies the array you call it on, which I suspect isn't your intention. See the answers to the linked questions for details and what to do instead. – T.J. Crowder Jan 30 '23 at 13:00

0 Answers0