An array is a container of multiple values of similar types. After initializing an array, how can you empty it? This tutorial will help you to empty an Array in JavaScript language.

Advertisement

Empty Array in JavaScript

Use the following syntax to empty an Array. Here myArray is the name of Array.

myArray = [];

The above code will create an Array named myArray with no content. If the myArray already exists, will lose all the existing elements.

You can also set the length to 0 to make it empty.

myArray.length = 0
Share.
Leave A Reply


Exit mobile version