Skip to content
Not available in DartThis function is not part of the Dart package. The documentation below is for JavaScript and Python.

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

NameTypeRequiredDefault
objobjectdict
searchKeystringstr
valueanyAny
recursivebooleanboolfalseFalse
upsertbooleanboolfalseFalse

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 }

Released under the MIT License