How to Empty an Array With JavaScript

Learn how to empty an array with JavaScript.

Emptying an array with JavaScript could not be more simple. Let’s say you have an array with a list of exercises:

let exerciseList = ["squat", "deadlift", "push-up", "pull-up"]

Use console.log(exerciseList) to print out your list of exercises and confirm that it works.

Now to empty your array, simply run the following:

exerciseList.length = ""

Now when you console.log(exerciseList) again, you’ll get an empty array:

console.log(exerciseList)
// output: []

Has this been helpful to you?

You can support my work by sharing this article with others, or perhaps buy me a cup of coffee 😊

Kofi

Share & Discuss on