0
What is the mean of this in JavaScript
arr=[]
5 ответов
+ 3
Yes, it deletes all elements.
+ 1
As Donna said, it's used for creating an array. If the brackets have nothing between them, you've either declared an empty array or you've emptied the contents.
Declaring empty array:
var arr = [];
Now fill the array:
arr = ["blue", "pink"];
arr[0] now = "blue"
arr[1] now = "pink"
Now empty the array:
arr = [];
+ 1
Duncan Not actually deleted though. Elements are removed from the array.
For elements passed by reference (a.k.a objects), emptying the array only remove a reference to the object.
0
Duncan if we empty the array again does this mean that the previous element in the array will automatically be deleted