string as variable name in javascript -
this question has answer here:
i have array of objects
: recs6
, recs7
, recs8
...... recs23
. want add factor in array using inner for
loop. 'recs+n' interpreted string , not variable name. how can make represent existing variables - rec6
, rec7
etc?
for(var n=6; n<24; n++){ for(var m=0; m<'recs+n'.length; m++){ hourbusyness += parsefloat(('recs'+n)[m].gtse); } houravgbusyness = hourbusyness / ('recs'+n).length; console.log(houravgbusyness); }
use this['recs'+n]
instead of ('recs'+n)
Comments
Post a Comment