How To Empty An Array In JavaScript
Here we consider how to empty an array in javascript.
Lets start with one example here.
Suppose we have an array in javascript as shown below.
var array = ["1", "2", "3"];
For clearing this array, you can use following method.
var array = ["1", "2", "3"];
array = [ ];
This will set the variable array to a new empty array.
Another method will be set the length of array to Zero.
var array = ["1", "2", "3"];
array.length = 0;