mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-01-31 15:27:50 +00:00
26 lines
506 B
JavaScript
26 lines
506 B
JavaScript
/**
|
|
* The inverse of `toPairs`is method returns an object composed
|
|
* from key-value `pairs`.
|
|
*
|
|
* @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) {
|
|
const result = {}
|
|
if (pairs == null) {
|
|
return result
|
|
}
|
|
for (const pair of pairs) {
|
|
result[pair[0]] = pair[1]
|
|
}
|
|
return result
|
|
}
|
|
|
|
export default fromPairs
|