1. Clear the array length

let arr = ['我'.'is'.'number'.'group'];
arr.length = 0;
Copy the code

2. Change the array pointer to a new empty array

arr = [];
Copy the code

Note that a lot of beginners make a mistake here. Assignment to an array is an address operation, so let’s print its type:

console.log(typeof arr);
object
Copy the code

It outputs an object, indicating that it is a reference type.

let arr2 = arr;
arr2.push('ha ha');
console.log(arr);
console.log(arr2);
Copy the code

After the execution:

[' 'I' '.' 'is' '.' 'The number' '.' 'group' '.' 'Ha ha' ']
[' 'I' '.' 'is' '.' 'The number' '.' 'group' '.' 'Ha ha' ']
Copy the code

And you can see that when you change the value of ARR2, arR also changes, because they’re referring to the same object.

3. Use the splice method to delete the entire array

arr.splice(0,arr.length);
Copy the code

4. Use the while loop to continually delete the last element of the array

while(arr.pop()){}
Copy the code

Welcome to add more ways ~~~