jeynon jeynon - 2 years ago 110
jQuery Question

Add a value to an JSON array

So I have an array that looks like this

[{"subbasinID":"1"},{"subbasinID":"2"}, etc....]

I need to add more values into each record. How do I ADD to an existing array so it might look something like this


I will know the name and value of the next group I need to add. I assume I have to identify which record I want and then append by finding the subbasinID. Not sure how! Thanks!

Answer Source

What you have is a list(array) of objects. All you need is to iterate the object and add elements to it.

var t = [{"subbasinID":"1"},{"subbasinID":"2"}/*, etc....*/]
t[0]["name"] = "John";
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download