Policies & Guidelines

REMOVE_ITEM_BY_KEY

Remove objects from array by a key

Description

Finds an object by a key-value pair and returns an array which doesn't contain the matched object.

For example, given Key "id" and Value 123, will return an array without the object whose id property is 123.

If a matching object cannot be found, the original array is returned unmodified.

Function signature

REMOVE_ITEM_BY_KEY(array: Array, key: String, value: ) => Array

Parameter

Description

Array

Array to remove object from

Key

Key whose value to match

Value

Value to match

Examples

array1 = [{"a":1},{"a":2},{"a":3}]
array2 = [{"a":3},{"a":{"b":10}}]
array3 = [{"a":3},{"a":2}]

Formula

Return value

REMOVE_ITEM_BY_KEY(array1, "a", 2)

[{"a":1},{"a":3}]

REMOVE_ITEM_BY_KEY(array2, "a", { b: 10 })

[{"a":3}]

REMOVE_ITEM_BY_KEY(array3, "a", 4)

[{"a":3},{"a":2}]