I have this javascript code which generate a multi array with static values:
var items = [ ["red", "blue"], ["green", "yellow"] ];
console.log(items[1][1]); // green
but now I would like to fill the values dynamically. I tried this:
var items = [[]];
$.each($("input[name='checkboxColors1']:checked"), function(){
items[0].push($(this).val());
});
$.each($("input[name='checkboxColors2']:checked"), function(){
items[1].push($(this).val());
});
items[0].push... works, but items[1] not
TypeError: items[1] is undefined
Where is my fault?
var items = [[]];thenitems[1]isundefined. You can'tpushinto undefined, you need to create the array first.