I have an array in javascript which has n elements. The number n is not known. How to delete all the elements from the array?

Member Avatar for stbuchok

The easy and quick way:

var arr = [];

the longer and harder way:

while (array.length > 0){
    array.pop();
}

The first one is easier and quicker.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.