I would like to create a multidimensional javascript array like this :
array('cats' => array(
'cat_1' => array(1, 2, 3 ...)
), array(
'cat_2' => array(....
I would like to add/remove "cat_id" and "tag_id" according to my variables...
var filter = {cats : [[]]};
function generateArray(cat_id, tag_id, add = true){
if(add == true)
filter.cats = [cat_id];
filter.cats[cat_id].push(tag_id);
} else {
//How to delete record the tag_id ?
//filter[cats][cat_id].(tag_id);
}
return filter;
}
generateArray(1, 1, true);
generateArray(2, 2, true);
generateArray(2, 3, true); etc...
I have this error message :
undefined is not object (evaluating filter.cats[cat_id].push
What's wrong ? Thanks in advance.