0
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.
let data := {
lastName: "Rogers",
firstName: "Steve"
};
setItem(data, "firstName", "Brian")
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.
let data := {
lastName: "Rogers",
firstName: "Steve"
};
setItem(data, "age", 112)
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.
Reply
Content aside
Related Articles