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.
setItem(JSON, string, any)
JSON
setItem(object, key, newValue)
Updates a key-value pair in a given JSON object.1
let data := {
2
lastName: "Rogers",
3
firstName: "Steve"
4
};
5
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.1
let data := {
2
lastName: "Rogers",
3
firstName: "Steve"
4
};
5
setItem(data, "age", 112)
Result: The object data is supplemented by the key-value pair
age: 112
.Last modified 7mo ago