Skip to content

filterEntries

filterEntries(object, predicate) → object · Object

Filter object properties by key and/or value. Returns a new object with only matching entries.

  • object (required): the object to filter

  • predicate (required): lambda (key, value) -> boolean

bash
echo '{"name": "Alice", "email": "alice@example.com", "password": "secret", "temp": null}' \
  | utlx -e 'filterEntries(., (key, value) -> value != null)'
# {"name": "Alice", "email": "alice@example.com", "password": "secret"}
utlx
{
  nonNull: filterEntries($input, (key, value) -> value != null),
  safe: filterEntries($input, (key, value) -> key != "password" && key != "temp")
}

Also: someEntry(obj, pred) → true if any entry matches, everyEntry(obj, pred) → true if all match, countEntries(obj, pred) → count of matching entries.

Released under AGPL-3.0.