• Home
  • JavaScript
  • How to clear (remove all items from) array in javascript?

How to clear (remove all items from) array in javascript?



There are several ways to remove all items from the array, the most popular are:



1. arr.length = 0;

This method cleans an existing array by setting its length to 0.



2. arr.splice(0, arr.length);

This method deletes items from position 0 to the last position in the array.

Joanna

Leave a Reply

Your email address will not be published. Required fields are marked *