To update or add a key-value pair in a given JSON object
With this function, you can update an already existing JSON object and add more data to it.
If your JSON object is stored in a variable, it will be modified even if the return value is not stored in the variable again.
setItem(JSON, string, any)
JSON
setItem(object, key, newValue)
Updates a key-value pair in a given JSON object.
Result: The object data is changed: The value assigned to the key firstName
is overwritten with the value Brian.
setItem(object, newKey, newValue)
Adds a key-value pair to a given JSON object.
Result: The object data is supplemented by the key-value pair age: 112
.
removeItem
, which removes a key-value pair from a given JSON object.