objUpdate
Changes the value matching a specific key name in the given object. If the recursive option is trueTrue, it will also search in child object items. This changes the value of the same key found in both the parent and child items. If the upsert option is trueTrue, add it as a new attribute to the top-level item when the key is not found.
Parameters
| Name | Type | Required | Default |
|---|---|---|---|
obj | objectdict | ● | – |
searchKey | stringstr | ● | – |
value | anyAny | ● | – |
recursive | booleanbool | – | falseFalse |
upsert | booleanbool | – | falseFalse |
Returns
object | null
dict | None
Examples
javascript
const result = objUpdate(
{
a: 1,
b: {
a: 1,
b: 2,
c: 3
},
c: 3
},
'c',
5,
true,
false
);
console.log(result); // Returns { a: 1, b: { a: 1, b: 2, c: 5 }, c: 5 }python
result = objUpdate(
{
'a': 1,
'b': {
'a': 1,
'b': 2,
'c': 3
},
'c': 3
},
'c',
5,
True,
False
)
print(result) # Returns { 'a': 1, 'b': { 'a': 1, 'b': 2, 'c': 5 }, 'c': 5 }