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.

Author: Joanna

I write code that (usually) works. I tame WordPress, learn React, explore the world of DevOps, and click around in the Linux console. I optimize code as a hobby, because laziness is the purest form of productivity. I do my best not to lose my mind somewhere between a bug and a deadline.

You can also like

Related posts