Skip to content

Function_evisit_core_js_data_toLookup

Wyatt Greenway edited this page Jan 31, 2017 · 1 revision

function toLookup(key, data)

Parameters

  • key
    • (String) Key to match on all objects. If key is undefined or null, the index will be used instead.
  • data
    • (Array) Array to create map from

Return value

  • (Object) Each key in the object will be the value in the Array specified by 'key'

Description

This takes an Array and returns a reference map for quick lookup.

See Also

Examples

var myMap = toLookup('id', [
{
  id:'derp',
  field: 'derp'
},
{
  id:'dog',
  field: 'dog'
},
{
  id:'cat',
  field: 'cat'
}
]);
myMap === {
'derp': {
  id:'derp',
  field: 'derp'
},
'dog': {
  id:'dog',
  field: 'dog'
},
'cat': {
  id:'cat',
  field: 'cat'
}
};

Clone this wiki locally