2016-10-10 03:43:44 +02:00
|
|
|
/**
|
|
|
|
* The inverse of `_.toPairs`; this method returns an object composed
|
|
|
|
* from key-value `pairs`.
|
|
|
|
*
|
|
|
|
* @static
|
|
|
|
* @memberOf _
|
|
|
|
* @since 4.0.0
|
|
|
|
* @category Array
|
|
|
|
* @param {Array} pairs The key-value pairs.
|
|
|
|
* @returns {Object} Returns the new object.
|
|
|
|
* @example
|
|
|
|
*
|
|
|
|
* _.fromPairs([['a', 1], ['b', 2]]);
|
|
|
|
* // => { 'a': 1, 'b': 2 }
|
|
|
|
*/
|
|
|
|
function fromPairs(pairs) {
|
|
|
|
var index = -1,
|
2016-11-03 01:33:53 +01:00
|
|
|
length = pairs == null ? 0 : pairs.length,
|
2016-10-10 03:43:44 +02:00
|
|
|
result = {};
|
|
|
|
|
|
|
|
while (++index < length) {
|
|
|
|
var pair = pairs[index];
|
|
|
|
result[pair[0]] = pair[1];
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = fromPairs;
|