Light ModeDark ModeReset dark mode. Falls back to OS dark mode setting.


No results for 'undefined'

Blog Posts

No results for 'undefined'
Powered by Algolia

How to Empty an Array With JavaScript

Oct 29, 20191 min readJavaScriptViews:

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: