repl.txt (1160B)
1 2 {{alias}}( collection, fcn[, thisArg] ) 3 Converts a collection to an object whose keys are determined by a provided 4 function and whose values are the collection values, iterating from right to 5 left. 6 7 When invoked, the input function is provided two arguments: 8 9 - `value`: collection value 10 - `index`: collection index 11 12 If more than one element in a collection resolves to the same key, the key 13 value is the collection element which last resolved to the key. 14 15 Object values are shallow copies. 16 17 Parameters 18 ---------- 19 collection: Array|TypedArray|Object 20 Input collection over which to iterate. If provided an object, the 21 object must be array-like (excluding strings and functions). 22 23 fcn: Function 24 The function to invoke for each element in a collection. 25 26 thisArg: any (optional) 27 Execution context. 28 29 Returns 30 ------- 31 out: Object 32 Output object. 33 34 Examples 35 -------- 36 > function toKey( v ) { return v.a; }; 37 > var arr = [ { 'a': 1 }, { 'a': 2 } ]; 38 > {{alias}}( arr, toKey ) 39 { '2': { 'a': 2 }, '1': { 'a': 1 } } 40 41 See Also 42 -------- 43