How do I add push a new object into the array if it doesn't exist?
I check this link: How to check if array element exists or not in javascript?
but not sure how to push the new object though!
var element = [];
element['obj'] = 'one';
if (typeof element['obj']['bg'] === 'undefined') {
console.log('not defined');
element['obj']['bg'] = 'red';
console.log(element);
} else {
console.log('defined');
}