I have added a dynamic json object with javascript. the code is as follow:
if (!beadz[color.title])
beadz.push({
(color.title): {
bead.title: {
"inventoryQuantity": bead.inventory_quantity,
"currentQuantity": 1
}
}
});
However the code is not working and giving syntax error. what i am missing? kindly help.
Hector Barbossa
5,53813 gold badges51 silver badges70 bronze badges
asked Jul 21, 2016 at 5:35
Sadaf Sid
1,5803 gold badges18 silver badges32 bronze badges
1 Answer 1
If you are using ES6
if(!beadz[color.title])
beadz.push({[color.title]:{[bead.title]:{"inventoryQuantity":bead.inventory_quantity,"currentQuantity":1}}});
answered Jul 21, 2016 at 5:39
Piyush.kapoor
6,8311 gold badge25 silver badges21 bronze badges
Sign up to request clarification or add additional context in comments.
Comments
lang-js
(color.title):is invalid syntax. Did you mean[color.title]:?