Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我刚刚遇到了这个 javascript 片段:
myArray.length--;
它究竟是做什么的?
这将删除数组中的最后一项。
var myArray = [1, 2, 3]; myArray.length--; alert(myArray);
输出是:
[1, 2]
简单的实验表明它切断了数组的最后一个元素。
> var a = [1, 2, 3]; => undefined > a => [1, 2, 3] > a.length-- => 3 > a => [1, 2]