DEV Community

Discussion on: 8 neat Javascript tricks you didn't know in 4 minutes.

Collapse
 
destroyer22719 profile image
Nathan Cai • Edited

Hey nice post, however "emptying array" can simply be done with array=[]

Collapse
 
jonrandy profile image
Jon Randy 🎖️

Technically not emptying the array, rather replacing it with a new empty one

Collapse
 
destroyer22719 profile image
Nathan Cai

but it still kinda achieves the exact same thing.

Thread Thread
 
jonrandy profile image
Jon Randy 🎖️

Not really. If you have another reference to the original array, and you use this method to 'empty' it - stuff is going to break as the other reference will still contain the unemptied array

Thread Thread
 
blessinghirwa profile image
Blessing Hirwa

Thanks for the support Nathan.

Thread Thread
 
blessinghirwa profile image
Blessing Hirwa

I've never met that kind of error but I'll try it in the future. Thanks for the assistance though.

Thread Thread
 
blessinghirwa profile image
Blessing Hirwa

I've never met that kind of error but I'll try it in the future. Thanks for the assistance though.

Thread Thread
 
industral profile image
Alex Ivasyuv

var a = [1, 2, 3]
var b = a;
a = [];
console.log(b); // [1, 2, 3]

Some comments have been hidden by the post's author - find out more