Ways to empty JavaScript array
There are different ways to empty an array in Javascript.
By assigning an empty arrayBy assigning array length to 0.
var numbers =[1,3,5,6]; numbers =[];
var letters = ["a", "b", "c"];
letters.length = 0;
By poping the elements of the array.
var randomIntegers =[1,4,5,6];
while(randomIntegers.length > 0) {
randomIntegers.pop();
}
By using .splice()var cities =["Mumbai","Pune"];
cities.splice(0, cities.length)
Comments
Post a Comment