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
+12.1k Golang : rune literal not terminated error
+18.4k Golang : Read a file into an array or slice example
+8.8k Golang : How to unmarshal JSON inner/nested value and assign to specific struct?
+28.4k Golang : How to check if a date is within certain range?
+5k Golang : How to detect if a sentence ends with a punctuation?
+3.8k Golang : How to deal with configuration data?
+36.3k Golang : How to count duplicate items in slice/array?
+3.3k Golang : Customize scanner.Scanner to treat dash as part of identifier
+11.6k Golang : Chunk split or divide a string into smaller chunk example
+30.7k Delete a directory in Go
+8.8k Golang : Calculate Relative Strength Index(RSI) example
+10.1k Swift : Convert (cast) Int or int32 value to CGFloat