Skip to content
Malexion edited this page Jan 13, 2017 · 3 revisions

__.index(obj, [key], [value])

  • obj Item to iterate over.
  • [key] [Optional] Function to find the hash key, should be unique. Defaults to (x, y) => y
  • [value] [Optional] Function to find the hash value. Defaults to x => x

Simple hashmap generator for fast array lookups via brackets [] instead of linear searches.

Examples

var array = [ 3, 5, 1, 0, 8 ];
var index = __.index(array, x => x, (x, y) => y);

// I want the array index of value 8 in my array
var idx = index[8];
Clone this wiki locally