+ 5
Let's say that I have a array with objects inside of it. What happens after I do array.shift(); with the object that dissapears?
Is that object deleted? Or where does it go?
6 ответов
+ 7
if you call shift function in an assignment,
let obj = arr.shift();
Then the object is stored in the variable obj;
If you call shift() without assignment,
arr.shift();
Then the object is destroy to memory space, following JavaScript garbage collection.
+ 4
You choose between shift(), pop() and splice() depends on your need.
https://code.sololearn.com/W3cNMx37R657/?ref=app
+ 3
I needed to delete the first element of a array.
Thanks fpr the help!
+ 2
💜 Alex Tușinean 🍇 ,
It might be lost if not used anywhere else from what i understood from that article :
https://javascript.info/garbage-collection
+ 2
Gordon is shift() a proper way to remove a object from a array?