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]
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.