Policies & Guidelines

EXCLUDE_BY_KEY

Remove objects from an array by a key

Description

Removes objects from an array by a given key-value pair.

Returns a new array which doesn't contain the matched objects, i.e. ones whose Key property's value matches Value.

For example, given Key "id" and Value 0, all objects in the source Array whose id property is 0 would be removed from the returned array.

Function signature

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

Parameter

Description

Array

Array to exclude objects from

Key

Key whose value to match

Value

Value to match

Examples

array1 = [{"a":3},{"a":2},{"a":4,"b":3},{"a":2,"b":5}]
key1 = "a"
value1 = 2
array2 = [{"a":3},{"a":{"b":10}}]
key2 = "a"
value2 = {"b":10}

Formula

Return value

EXCLUDE_BY_KEY(array1, key1, value1)

[{"a":3},{"a":4,"b":3}]

EXCLUDE_BY_KEY(array2, key2, value2)

[{"a":3}]