+ 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?

8th Dec 2020, 2:21 PM
🍇 Alex Tușinean 💜
🍇 Alex Tușinean 💜 - avatar
6 odpowiedzi
+ 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.
8th Dec 2020, 5:00 PM
Gordon
Gordon - avatar
+ 4
You choose between shift(), pop() and splice() depends on your need. https://code.sololearn.com/W3cNMx37R657/?ref=app
8th Dec 2020, 5:59 PM
Gordon
Gordon - avatar
+ 3
I needed to delete the first element of a array. Thanks fpr the help!
8th Dec 2020, 6:02 PM
🍇 Alex Tușinean 💜
🍇 Alex Tușinean 💜 - avatar
+ 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
8th Dec 2020, 3:02 PM
EmmanueLZ.
EmmanueLZ. - avatar
+ 2
Gordon is shift() a proper way to remove a object from a array?
8th Dec 2020, 5:28 PM
🍇 Alex Tușinean 💜
🍇 Alex Tușinean 💜 - avatar