I work with javascript and JSON. I have a JSON object similar to this:
{"firstName":"John", "lastName":"Doe", "id":"1"}
In my case, I have a function like this:
function addNewValues(jsonArray, firstName, lastName, id)
If the "firstName" does not match, I must create a new value in the array.
Of
addNewValues({"firstName":"John", "lastName":"Doe", "id":"1"}, "Jane",
"Doe", "2");
he must return:
[
{"firstName":"John", "lastName":"Doe", "id":"1"},
{"firstName":"Jane", "lastName":"Doe", "id":"2"}
]
How can I add this new position? I tried myObj.push({"firstName":firstName, "lastName":lastName });
without any success.
Thanks in advance.
source
share