-1

I have this code, but I want the belongsto var to be retrieved as the key using the var value and not the var name:

var belongsto = panel.attr('data-belongsto');
var panelid = panel.attr('id');

tabValue.push({belongsto:panelid}); console.log(tabValue);

this returns [{'belongsto':'12345'}]

As you can see the the script takes belongsto as the key name but I need it to take the content of the variable.

Any help is appreciated, thanks-

Ultranuke
  • 1,735
  • 2
  • 15
  • 21

1 Answers1

0

Create the object first

var obj = {};
obj[belongsto] = panelid;
tabValue.push(obj);
Sean
  • 779
  • 6
  • 18