Hi Friends 👋,
Welcome To Infinitbility! ❤️
splice() method with array length it will delete all elements of the array without compromise with reference, and also it is one of the fastest ways to empty an array.
The splice() method takes the index (from which the splicing should start ) and the number of items to be removed as parameters and splices the elements.
We have to pass the 0 as an index (the first element) and the length of the array as parameters that ends up emptying the whole array. The performance of this method is almost as fast as assigning the new array method
splice() method to empty the array.
Here, we will create an array with some data, and then we will use the
splice() method to remove all elements of the array.
let arr = ["Infinitbility","aguidehub","sortoutcode"] arr.splice(0, arr.length) console.log(arr) // output: ""
I hope it helps you, All the best 👍.