JAVAvladuxa JAVAvladuxa - 1 year ago 69
AngularJS Question

Creating obj with dynamically changeable name

I am going to create some count of object with specific names.

if i do

var obj = {}
obj.A = ['a', 'b', 'c'];

that create key A with array value

Can I do something like this:

var obj = {}
var keyName = 'A';

obj.keyName = ['a', 'b', 'c'];

And obj containe name of key A and array as value.
Is it possible?

Answer Source

Just do

obj[keyName] = ['a', 'b', 'c'];
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download