I am trying to push the objects to an array and the differences of the objects are just one property.
Code snippet:
var categoryList = ['product1', 'product2', 'product3'...more]
var productlist = [];
var date = new Date();
var year = date.getFullYear();
var nextYear = year++
for (var a = 0; a < categoryList.length; a++) {
productList.push({
date: year + '-' + categoryList[a],
'items': [{
'quatity': 0 'type': 'new'
}]
});
productList.push({
date: nextYear + '-' + categoryList[a],
'items': [{
'quantity': 0 'type': 'new',
}]
});
}
I need to add this year and next year to the object but I am not sure if there are any better ways to simplified the above codes. Thanks for the help!
...more]" is illegal. Do not sacrifice proper syntax for laziness. I hope you don't run your JavaScript through JSHint. God forbid you use JSLint. Douglas Crockford would have a hayday...