清空数组

Avatar of Chris Coyier
Chris Coyier

这是清空数组最快捷、最简单的方法之一。当然还有其他方法,但通常涉及创建新数组。这种方法可以重复使用同一个数组。

var myArray = ["one", "two", "three"];

// console.log( myArray ) => ["one", "two", "three"]

myArray.length = 0;

// console.log( myArray ) => []