setItem
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.
Syntax
setItem(JSON, string, any)
Return
JSON
Examples
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
.
See also
removeItem
, which removes a key-value pair from a given JSON object.
Last updated