Example 1: Empty Array by Substituting New Array
Output
[1, 2, 3] []
In the above program, the value of array is substituted by a new empty array.
Example 2: Empty Array Using splice()
Output
[1, 2, 3] []
In the above program, the splice() method is used to remove all the elements of an array.
In the splice() method,
- The first argument is the index of an array to start removing an item from.
- The second argument is the number of elements that you want to remove from the index element.
Example 3: Empty Array by Setting Length 0
Output
[1, 2, 3] []
In the above program, the length property is used to empty the array.
When setting array.length to 0, all the elements of the array are removed.