How to Clear an Array in JavaScript

There are different ways to empty an array in javascript, we have mentioned 4 ways to clear an array using javascript.

For example we have javascript array variable:

Let’s check out different ways to empty an array.

1) Setting array length to zero:

In this method, set array variable lenght to zero.

2) Assign it to new empty array:

This is the quick way to cleat an array in javascript.

3) Using pop() method:

using this pop() method you can remove each array element via using while loop.

This is quite slowest process to empty an array.

4) Use splice() method:

In this way to clear an array, the splice() method will removed all elements and returned the empty array.

Recommended Posts For You

About Harish

I am professional web developer and blogger. Use this blog to share own api and other web development experience with you. I do accept paid work. Write to me at - [email protected]

View all posts by Harish