input collection
function to invoke
execution context
output object
function toKey( value, index ) {
console.log( '%d: %s', index, JSON.stringify( value ) );
return value.name;
}
var collection = [
{ 'name': 'beep', 'a': 1 },
{ 'name': 'boop', 'b': 2 }
];
var obj = keyByRight( collection, toKey );
// returns { 'boop': { 'name': 'boop', 'b': 2 }, 'beep': { 'name': 'beep', 'a': 1 } }
Converts a collection to an object whose keys are determined by a provided function and whose values are the collection values, iterating from right to left.
Notes
When invoked, the input function is provided two arguments:
value
: collection valueindex
: collection indexIf more than one element in a collection resolves to the same key, the key value is the collection element which last resolved to the key.
Object values are shallow copies.