The _.indexBy(list, iteratee) function from the Underscore library in Javascript creates an object composed of keys generated from the results of running each element of list through an iteratee function.
The code below demonstrates how to use _.indexBy() function with an array of objects:
index.tsx394 chars18 linesIn the example above, the persons array is indexed by the name property of each object using the _.indexBy() function. The resulting object has keys generated from each person's name and values that are the corresponding person object.
gistlibby LogSnag