Skip to content

objDeleteKeyByValue

Deletes keys equal to the given value from the object data. If the recursive option is true, also deletes all keys corresponding to the same value in the child items.

Parameters

NameTypeRequiredDefault
objobject
searchValuestring | number | null
recursivenamedbooleanfalse

named parameters are passed as named parameters in Dart and keyword arguments in Python.

Returns

object|null

Examples

javascript
const result = objDeleteKeyByValue(
	{
		a: 1,
		b: 2,
		c: {
			aa: 2,
			bb: {
				aaa: 1,
				bbb: 2
			}
		},
		d: {
			aa: 2
		}
	},
	2,
	true
);

console.log(result); // Returns { a: 1, c: { bb: { aaa: 1 } }, d: {} }
dart
print(objDeleteKeyByValue(
    {
      'a': 1,
      'b': 2,
      'c': {
        'aa': 2,
        'bb': {
          'aaa': 1,
          'bbb': 2
        }
      },
      'd': {
        'aa': 2
      }
    },
    2,
    recursive: true
));
// Returns { 'a': 1, 'c': { 'bb': { 'aaa': 1 } }, 'd': {} }
python
result = objDeleteKeyByValue(
	{
		'a': 1,
		'b': 2,
		'c': {
			'aa': 2,
			'bb': {
				'aaa': 1,
				'bbb': 2
			}
		},
		'd': {
			'aa': 2
		}
	},
	2,
	True
)

print(result)  # Returns { 'a': 1, 'c': { 'bb': { 'aaa': 1 } }, 'd': {} }

Released under the MIT License