JavaScript set anonymous Object key to variable name -
var curr = data[i], newarray = [], key = curr.frequency.type, obj = {key: []}; newarray.push(obj);
however, yields object key of "key"! how can create new object key of value of variable key
?
you can this:
var curr = data[i], newarray = [], key = curr.frequency.type, obj = {}; obj[key] = []; newarray.push(obj);
there's no way in javascript within object literal itself; syntax doesn't provide that.
Comments
Post a Comment