Debian Codegraph @

node/lodash/fromPairs.js

raw
1 var baseAssignValue = require('./_baseAssignValue');
2
3 /**
4 * The inverse of `_.toPairs`; this method returns an object composed
5 * from key-value `pairs`.
6 *
7 * @static
8 * @memberOf _
9 * @since 4.0.0
10 * @category Array
11 * @param {Array} pairs The key-value pairs.
12 * @returns {Object} Returns the new object.
13 * @example
14 *
15 * _.fromPairs([['a', 1], ['b', 2]]);
16 * // => { 'a': 1, 'b': 2 }
17 */
18 function fromPairs(pairs) {
19 var index = -1,
20 length = pairs == null ? 0 : pairs.length,
21 result = {};
22
23 while (++index < length) {
24 var pair = pairs[index];
25 baseAssignValue(result, pair[0], pair[1]);
26 }
27 return result;
28 }
29
30 module.exports = fromPairs;