I have this array
query = { x: { y: z } }
I tried like this but jquery makes my vars as constant key
var x = "one";
var y = "two";
var z = "three";
var query = { x: { y: z } }
I have this array
query = { x: { y: z } }
I tried like this but jquery makes my vars as constant key
var x = "one";
var y = "two";
var z = "three";
var query = { x: { y: z } }
You can use bracket notation to achieve that.
var query = {}, obj = {}; // objects
obj[y] = z;
query[x] = obj;
console.log(query);
Try this:-
var query;
query[x]={};
query[x][y]=z;
It seems you want to create a hashtable and use some variables as keys. You can do this by creating a hashtable and then setting values as follows
var query = {},
x = 'one',
y = 'two',
z = 'three';
query[x] = {};
query[x][y] = z