1let aray = [1,2,3,4,5,6,7,8,9,10];
2
3//as with most coding there are several ways you can do anything
4//see whichever works best for your scenario
5
6//set the array to equal a blank array
7array = [];
8
9//set the array's length to 0
10array.length = 0;
11
12//using splice, starts at index 0 & removes everything up to and including that last index
13array.splice(0, array.length);
14
15//map or loop through and shift() or pop();
16//goes through the array one at a time and removes the last item each time
17array.map( () => array.pop());
18
19//goes through the array one at a time and removes the first item each time
20array.map( () => array.shift());
1let list = [1, 2, 3, 4];
2function empty() {
3 //empty your array
4 list.length = 0;
5}
6empty();
7
1var list = [1, 2, 3, 4];
2function empty() {
3 //empty your array
4 list.length = 0;
5}
6empty();
7