Policies & Guidelines

WITH_UNIQUE_ITEM_BY_KEY

Add item to the array, unique by given key

Description

Returns the array with the given item added, but only if the array doesn't already have an object whose Key value matches the given item's Key value.

Function signature

WITH_UNIQUE_ITEM_BY_KEY(array: Array, item: Object, key: String) => Array

Parameter

Description

Array

Array to add item to

Item

Item to add

Key

Key whose values to compare to ensure uniqueness

Examples

Formula

Return value

WITH_UNIQUE_ITEM_BY_KEY([{ a: 3, b: 10 }, { a: 2, b: 11 }], { a: 10 } , "a")

[{"a":3,"b":10},{"a":2,"b":11},{"a":10}]

WITH_UNIQUE_ITEM_BY_KEY([{ a: 3, b: 10 }, { a: 2, b: 11 }], { a: 2 } , "a")

[{"a":3,"b":10},{"a":2,"b":11}]