Code Snippets Gallery
Empty an Array
This is one of the fastest and easiest ways of emptying an array. Of course there are may other ways, but those usually include creation of a new array. This way you reuse the same array.
var myArray = ["one", "two", "three"];
// console.log( myArray ) => ["one", "two", "three"]
myArray.length = 0;
// console.log( myArray ) => []
isnt:
myArray = [];
just as good?
I bet this:
myArray.length = 0;does not work in all browsers where the snippet provided above – does.
Excellent code, myArray.empty() works as well.