JQuery结合变量名称

时间:2013-11-22 06:38:07

标签: javascript object

假设我有这样的变量:

localStorage.var1a = 0;
localStorage.varnum = 1000;

这样的代码:

for(x = 1; x <localStorage.varnum;x++){
  if(localStorage.var.x.a > 0){
     localStorage.var.x.a  = Number(localStorage.var.x.a)
  }else{
     localStorage.var.x.a = 0;
  }
}

我的问题是,我不知道如何组合x和localStorage.var * a;

1 个答案:

答案 0 :(得分:0)

  if(localStorage["var"+x+"a"] > 0){
     localStorage["var"+x+"a"]  = Number(localStorage["var"+x+"a"]);
  }else{
    localStorage["var"+x+"a"]= 0;
  }