Description
Creates a new map containing only the specified keys from the input map. This is the inverse ofremoveKeys.
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
Example 2: Selecting Specific Node Properties
Example 3: Building API Response with Selected Fields
Example 4: Handling Non-Existent Keys
Example 5: Dynamic Field Selection
Notes
- Returns empty map if input is not a valid object or keys is not an array
nullvalues 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
- map.removeKeys - Remove specific keys (inverse operation)
- map.removeKey - Remove a single key
- map.merge - Combine multiple maps
Frequently Asked Questions
What does flex.map.submap do?
What does flex.map.submap do?
It extracts a subset of key-value pairs from a map, returning a new map containing only the specified keys.
What happens if a requested key does not exist in the map?
What happens if a requested key does not exist in the map?
Missing keys are simply omitted from the resulting submap — no error is thrown.