If I have a JSON structure that looks something like this:
var user = {
map: {
width: 785,
height: 791
},
image: {
name: "image.png",
size: {width:32}
},
properties:[{
firstName: "Bob",
lastName: "Jones",
}]
};
How would I change (after creation) the value of the firstName property to "Jane"?
I am fairly new to JSON, and I'm just trying to figure out how to make this one change for now. Any help would be greatly appreciated.
Well, one reason for your confusion might be that this is not JSON at all. JSON is a text format used for serialising objects. This is just a literal object in Javascript.
To change the firstName property, you would access the first item in the properties array in the user object:
user.properties[0].firstName = "Jane";
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With