1

I have an object:

var JSONObject = {
    "thing": {
        "array": [{
            "a": "aaa"
        }]
    }
};

And I'm trying to push another object here:

var JSONObject = {
    "thing": {
        "array": [{
            "a": "aaa",
            "NEW THING": "GOES HERE"
        }]
    }
};

Normally, you would do:

JSONObject.thing.array.push({"NEW THING": "GOES HERE"})

But in this case I can't do that, since there's no real handle to the object; it's undefined.

Any ideas would be greatly appreciated!

Thanks.

0

1 Answer 1

3

Do

JSONObject.thing.array[0]["NEW THING"] = "GOES HERE";

This

{
   "a": "aaa"
}

is not an array, but an object and you want to insert a new key value pair.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.