0
An item in an array remove
I'm making a filter for change an item undefined but why there is an item remove,too This is the code : https://code.sololearn.com/WyFMfV8mcRrk/?ref=app Explain to me why this is happened ? And thanks before
3 odpowiedzi
+ 2
first argument is starting index.
second argument is amount of item to be removed. now both index and amount is i at 2, so it removes two elements.
as you want to replace undefined, you should use 1 instead of i as second argument.
the amount can be 0, if zero element to remove, means insert before that index.
see Mozilla doc example.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/splice
when you want to understand a JavaScript function, always read Mozilla doc.
+ 1
because the second argument of splice is how many element to take out.
If you want to remove one only,
.... splice(i, 1,...)
0
Gordon Isn't the second set of splice an index to be erased? Or the amount of items that must be removed?