Skip to content

How to Empty an Array in JavaScript

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

Rahul Kumar is the founder and chief editor of TecAdmin.net. A Red Hat Certified Engineer (RHCE), he has worked in IT since 2009, with hands-on experience in Linux system administration, DevOps, web hosting, cloud platforms and automation. He started TecAdmin in 2013 to share practical, step-by-step guides, and leads its editorial work with one aim: making technical learning clear and useful for sysadmins, developers and beginners alike.

Leave a Reply

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


Back to top