arr.length = 0;
// Or assign it to an empty array
arr = [];
arr = []
creates a new array and doesn't affect other references.let foo = ['hello', 'world'];
// Add a reference
let bar = foo;
foo = [];
// `bar` isn't affected
console.log(bar); // ['hello', 'world']
arr.length = 0
modifies the array. All references are affected.let foo = ['hello', 'world'];
let bar = foo;
foo.length = 0;
// `bar` is affected
console.log(bar); // []
arr.splice(0, arr.length);
.splice
returns an array of removed items, you can get a copy of original array
by assigning the result to a new variable:let foo = ['hello', 'world'];
// Empty and create a copy of `foo`
let bar = foo.splice(0, foo.length);
console.log(foo); // []
console.log(bar); // ['hello', 'world']
[]
.const foo = [1, 2, 3];
foo = []; // will throw an exception of
// "Assignment to constant variable"
foo.length = 0;