Skip to content
Advertisement

array.splice() removes the content of an entry but not an entry itself

I am trying to remove an entry from an array using array.splice(), using this bit of code:

let replaceThisArrRemoved = replaceThisArr.splice(positionNumber, 1);

When I use replaceThisArr = ["apple", "orange", "pear"] and positionNumber = 1, it will return replaceThisArr = ["apple", "", pear"].

I am trying to get it to return replaceThisArr = ["apple", "pear"]

Is there any other way of doing this, or anything wrong with my code that I should fix?

Advertisement

Answer

look at this console output –

enter image description here

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement