main
Last change
on this file since d565449 was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago |
Update repo after prototype presentation
|
-
Property mode
set to
100644
|
File size:
594 bytes
|
Line | |
---|
1 | /**
|
---|
2 | * The inverse of `_.toPairs`; this method returns an object composed
|
---|
3 | * from key-value `pairs`.
|
---|
4 | *
|
---|
5 | * @static
|
---|
6 | * @memberOf _
|
---|
7 | * @since 4.0.0
|
---|
8 | * @category Array
|
---|
9 | * @param {Array} pairs The key-value pairs.
|
---|
10 | * @returns {Object} Returns the new object.
|
---|
11 | * @example
|
---|
12 | *
|
---|
13 | * _.fromPairs([['a', 1], ['b', 2]]);
|
---|
14 | * // => { 'a': 1, 'b': 2 }
|
---|
15 | */
|
---|
16 | function fromPairs(pairs) {
|
---|
17 | var index = -1,
|
---|
18 | length = pairs == null ? 0 : pairs.length,
|
---|
19 | result = {};
|
---|
20 |
|
---|
21 | while (++index < length) {
|
---|
22 | var pair = pairs[index];
|
---|
23 | result[pair[0]] = pair[1];
|
---|
24 | }
|
---|
25 | return result;
|
---|
26 | }
|
---|
27 |
|
---|
28 | export default fromPairs;
|
---|
Note:
See
TracBrowser
for help on using the repository browser.