Reputation: 1827
I just ran across this javascript snippet:
myArray.length--;
What does it do exactly?
Upvotes: 1
Views: 2717
Reputation: 28120
This removes the last items in the array.
var myArray = [1, 2, 3];
myArray.length--;
alert(myArray);
The output is:
[1, 2]
Upvotes: 4
Reputation: 230346
Simple experimentation shows that it chops off last element of the array.
> var a = [1, 2, 3];
=> undefined
> a
=> [1, 2, 3]
> a.length--
=> 3
> a
=> [1, 2]
Upvotes: 3