Description
Converts a list of key-value pairs into a map. Each pair should be a two-element array[key, value].
Syntax
Parameters
Returns
Type: map (object) A map where each key-value pair from the input list becomes a property. Returns an empty map if input is not an array.Examples
Example 1: Basic Conversion
Example 2: Converting Zipped Data
Example 3: Dynamic Property Creation
Example 4: Converting Query Results to Lookup Map
Notes
- Returns empty map if input is not an array or is
null - Each pair must be a two-element array; invalid pairs are skipped
- If a key is
nullorundefined, the pair is ignored - Duplicate keys result in the last value being used
- Keys are converted to strings as map property names
See Also
- coll.zip - Create pairs from two lists
- map.submap - Extract subset of keys from a map
Frequently Asked Questions
What format does flex.map.fromPairs expect?
What format does flex.map.fromPairs expect?
It expects a list of two-element lists (pairs) where the first element is the key and the second is the value:
[['key1', 'val1'], ['key2', 'val2']].What happens with duplicate keys in the pairs list?
What happens with duplicate keys in the pairs list?
Later pairs overwrite earlier ones — the last value for a given key wins.