Javascript : Empty an array example
Problem :
You have an array in JavaScript and you need to empty it. How to do that?
For instance :
arr := [0,1,2,3,4,5]
Solutions :
1.
while(arr.length > 0) {
arr.pop();
}
2.
arr.length = 0;
3.
arr = [];
By Adam Ng
IF you gain some knowledge or the information here solved your programming problem. Please consider donating to the less fortunate or some charities that you like. Apart from donation, planting trees, volunteering or reducing your carbon footprint will be great too.
Advertisement
Tutorials
+6k Java : Human readable password generator
+13.1k Golang : Convert(cast) int to int64
+10k Golang : Test a slice of integers for odd and even numbers
+17.5k Golang : Find smallest number in array
+50.9k Golang : Disable security check for HTTPS(SSL) with bad or expired certificate
+12.2k Golang : How to display image file or expose CSS, JS files from localhost?
+6.6k Golang : When to use make or new?
+7.5k Golang : How to handle file size larger than available memory panic issue
+25.2k Golang : Storing cookies in http.CookieJar example
+51.3k Golang : Check if item is in slice/array
+17.6k Golang : Defer function inside init()
+16.2k Golang : Loop each day of the current month example