I need to dynamically create a json object full of cats and sub cats. My structure looks like this
var cats = {
tops: {
'top' : {
link : 'link',
subs : [
{
'sub' : {
link : 'a link'
}
}
]
}
}
};
Now I can add a top level category no problem with cats.tops[topVar] = { link : topLinkVar };
However I need to add subs
categories to the top
category.
I have tried a few variations such as cats.tops[topVar].subs.push( { subVar : { link : subLinkVar } } );
But this produces an undefined error.
The trick is that the sub categories need to be an array, so each top category can have many sub categories. What am I missing?