Let's say I have a JSON list like this:
var obj = {"1": "somevalue", "2": "someothervalue"};
How can I add {"3": "somevalue"}
to the object dynamically? i.e. without knowing that two keys already that exist.
I'm looking for some JavaScript that looks at the JSON list, then adds a key to the end without accidentally overwriting an existing key.
I understand there is a similar question here: Checking if a key exists in a JavaScript object? but I would like to know how to dynamically generate the next number key e.g. "3" in the example above.