i want to create an object dynamically of the form - {"abc": [x1,x2], "efg": [x3, x4, x1]} The following code is not working.. what s the problem here ?
var catCmp = {};
var x1="abc";
var x2="efg";
var y1="x1";
var y2="x2";
var y3="x3";
var y4="x4";
if (typeof catCmp[x1] === undefined ) {
catCmp[x1] = [];
}
if (typeof catCmp[x2] === undefined ) {
catCmp[x2] = [];
}
catCmp[x1] = catCmp[x1].push(y1);
catCmp[x1] = catCmp[x1].push(y2);
catCmp[x2] = catCmp[x2].push(y3);
catCmp[x2] = catCmp[x2].push(y4);
catCmp[x2] = catCmp[x2].push(y1);
console.log( catCmp ::: , catCmp);