I have a for loop which basically goes through a list of categories. Each category (string) has 4 different items which can either be a true or a false. Below is a snippet of my code:
var i,
category,
items,
categories= {};
for (i = 0; i < categories.length; i++) {
category = categories[i];
items = {};
items.first = availableItems[i][0] == true;
items.second = availableItems[i][1] == true;
items.third = availableItems[i][2] == true;
items.fourth = availableItems[i][3] == true;
categories+= { category : items};
}
What i would like to end up is with a categories object structure like the below:
{ category1 : {
first : true,
second : true,
third : false,
fourth : true
},
category2 : {
first : true,
second : true,
third : false,
fourth : false
},
category3 : {
first : true,
second : true,
third : false,
fourth : false
}
}
Can anyone tell me what I am doing wrong?