Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
171
rated 0 times [  176] [ 5]  / answers: 1 / hits: 121808  / 15 Years ago, mon, january 11, 2010, 12:00:00

Is there a way to assign a default values to arrays in javascript?



ex: an array with 24 slots that defaults to 0


More From » arrays

 Answers
13
Array.prototype.repeat= function(what, L){
while(L) this[--L]= what;
return this;
}


var A= [].repeat(0, 24);



alert(A)


[#97862] Friday, January 8, 2010, 15 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
annalise

Total Points: 210
Total Questions: 94
Total Answers: 102

Location: The Bahamas
Member since Tue, Apr 27, 2021
3 Years ago
annalise questions
Mon, May 24, 21, 00:00, 3 Years ago
Wed, May 5, 21, 00:00, 3 Years ago
Sat, Sep 12, 20, 00:00, 4 Years ago
Tue, Jul 28, 20, 00:00, 4 Years ago
;