I just ran across this javascript snippet:
myArray.length--;
What does it do exactly?
I just ran across this javascript snippet:
myArray.length--;
What does it do exactly?
This removes the last items in the array.
var myArray = [1, 2, 3];
myArray.length--;
alert(myArray);
The output is:
[1, 2]
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]