There are three method to empty the array list
Method1:- arrayList defined empty array.
Syntax:-
var arrayList=[];
Example:-
var array_list = ['a', 'b', 'c', 'd', 'e', 'f']; // Created array
var new_array_list = array_list; // Referenced arrayList by another variable
array_list = []; // Empty the array
console.log(array_list); //Output []
console.log(new_array_list); // Output ['a', 'b', 'c', 'd', 'e', 'f']
Note:- if you changed original array variable then reference array will remain unchanged.
Method2:-
Syntax:-
var arrayList.length=0;
Example:-
var array_list = ['a', 'b', 'c', 'd', 'e', 'f']; // Created array
var new_array_list = array_list; // Referenced array_list by another variable
array_list.length = 0; // Empty the array by setting length to 0
console.log(array_list); // Output []
console.log(new_array_list); // Output []
Note:- This way of empty the array also update all the reference variable which pointing to the original array.
Method3:-
Syntax:-
arrayList.splice(0, arrayList.length);
Example:-
var array_list = ['a', 'b', 'c', 'd', 'e', 'f']; // Created array
var new_array_list = array_list; // Referenced array_list by another variable
array_list.splice(0, array_list.length); // Empty the array by setting length to 0
console.log(array_list); // Output []
console.log(new_array_list); // Output []