0

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.

3
  • please provide the json you are using Commented Jul 21, 2016 at 5:38
  • Why don't you tell us what syntax error you get? Commented Jul 21, 2016 at 5:39
  • (color.title): is invalid syntax. Did you mean [color.title]:? Commented Jul 21, 2016 at 5:48

1 Answer 1

1

If you are using ES6

if(!beadz[color.title])

                beadz.push({[color.title]:{[bead.title]:{"inventoryQuantity":bead.inventory_quantity,"currentQuantity":1}}});
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.