I'm trying to create an instance of the elements that have been added using the splice() function.
var myFish = ['angels', 'clowns', 'starfish', 'sharks'];
var removed = myFish.splice(2,1, "spongebob");
console.log(removed); //
The output I'm looking for is spongebob but instead I get starfish.
Any thoughts?
starfishwithspongebobbecause if so, you did that successfully.removedis showing the element that yousplicedout of thearray. If you actuallyconsole.log(myFish), you will see that yourarraynow includesspongebob.removedfor a reason.splicein the first place if you don't want the removed item? Simply do:var added = myFish[2] = "spongebob";