默认数组值 [英] default array values
本文介绍了默认数组值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有没有指定一个默认值在JavaScript中数组的方式?
例如: 24插槽的数组,默认为0
解决方案
Array.prototype.repeat =功能(什么,L){
而(L)本[ - L] =什么;
返回此;
}
VAR A = [] .repeat(0,24);
警报(A)
Is there a way to assign a default values to arrays in javascript?
ex: an array with 24 slots that defaults to 0
解决方案
Array.prototype.repeat= function(what, L){
while(L) this[--L]= what;
return this;
}
var A= [].repeat(0, 24);
alert(A)
这篇关于默认数组值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文