I was trying to remove certain elements based on their index in array. example:
var x = ["a","b","c"];
and trying to do
x.splice(x.indexOf("d"),1)
Since this turns out to be x.splice(-1,1)
- it's ending up removing the element "c" from the array!
unable to understand why this is happening even though there is no cyclic property for Arrays in javascript.
From the MDN page for splice
:
If negative, will begin that many elements from the end.
So x.splice(-1, 1)
starts one element from the end of x
and deletes a single element.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With