Skip to content

How to Empty an Array in JavaScript

Advertisement

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.

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

Rahul

I, Rahul Kumar am the founder and chief editor of TecAdmin.net. I am a Red Hat Certified Engineer (RHCE) and working as an IT professional since 2009..

Leave a Reply

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


Back to top