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

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -