-1

How can I delete all the items from a JavaScript array?

example -

var myArray1, 2, 3, 4, 5, 6, 7, 8, 9];

// I want it to become this
myArray = [];
Arittra
  • 9
  • 1

1 Answers1

1

You can try this:

function clearArray(array) {
  while (array.length) {
    array.pop();
  }
}
Utsav Shrestha
  • 77
  • 1
  • 10