2
For example:
var frutas = ["goiaba", "manga", "laranja", "abacate"];
frutas.splice(1, 1);
This code, instead of removing 1 item from the second index of my array (1), only returns the item I want to delete, which in this case is "orange";
That is, instead of returning ["goiaba", "manga", "abacate"]
- he returns ["laranja"]
;
From what I understood in what I read/researched about, the Array.prototype.splice()
serves to do what I’m trying there. Am I right? If so, why this method behavior splice
?
NOTE: browser Google Chrome version 60
For documentation on MDN on the return of the function: "A list containing the removed elements.". It seems you’ve got it all wrong.
– Woss
Do this where @Andersoncarloswoss said and removes the element from the array. If you see the contents of your fruit array it will be
["goiaba", "laranja", "abacate"]
as expected.– fernandoandrade
Now I get it... I thought splice would return a new Array without the item being removed. Thank you both so much.
– Seu Madruga
I must remove the question?
– Seu Madruga