Skip to main content

Description

Creates a new map containing only the specified keys from the input map. This is the inverse of removeKeys.

Syntax

Parameters

Returns

Type: map (object) A new map containing only the specified keys and their values from the input map. Returns an empty map if input is not a valid object or keys is not an array.

Examples

Example 1: Basic Submap Extraction

Output:

Example 2: Selecting Specific Node Properties

Example 3: Building API Response with Selected Fields

Example 4: Handling Non-Existent Keys

Output:
(Only existing keys are included)

Example 5: Dynamic Field Selection

Notes

  • Returns empty map if input is not a valid object or keys is not an array
  • null values in the keys array are ignored
  • Non-existent keys are silently skipped
  • Creates a new map; does not modify the original
  • Useful for selecting specific fields, building API responses, or data projection
  • More efficient than manually picking each field

See Also

Frequently Asked Questions

It extracts a subset of key-value pairs from a map, returning a new map containing only the specified keys.
Missing keys are simply omitted from the resulting submap — no error is thrown.