Javascript
100 Front End Interview Questions Challenge

Empty Arrays

Mute
Current Time 0:00
/
Duration Time 0:00
Loaded: 0%
Progress: 0%
Stream TypeLIVE
Remaining Time -0:00
 
PRO

The most common way to empty an array is by reassigning it to an empty array: array = [].

But what if the array is a const and you need to empty it by modification rather than reassignment? Here are two of the simplest strategies:

  • array.length = 0
  • array.splice(0)
 

I finished! On to the next chapter