javascript你可能不知道的3

var arr=[1,2,3,4,5];
delete(arr[2]);
alert(arr.length);
alert(arr);
看看结果,是不是有点意外呢?
var arr=[1,2,3,4,5];
arr.length=3;
alert(arr);
length还是可写的。这样能方便得截短一个数组。

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.