Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
80742 views
1
var keys = require('./keys'),
2
toObject = require('../internal/toObject');
3
4
/**
5
* Creates a two dimensional array of the key-value pairs for `object`,
6
* e.g. `[[key1, value1], [key2, value2]]`.
7
*
8
* @static
9
* @memberOf _
10
* @category Object
11
* @param {Object} object The object to query.
12
* @returns {Array} Returns the new array of key-value pairs.
13
* @example
14
*
15
* _.pairs({ 'barney': 36, 'fred': 40 });
16
* // => [['barney', 36], ['fred', 40]] (iteration order is not guaranteed)
17
*/
18
function pairs(object) {
19
object = toObject(object);
20
21
var index = -1,
22
props = keys(object),
23
length = props.length,
24
result = Array(length);
25
26
while (++index < length) {
27
var key = props[index];
28
result[index] = [key, object[key]];
29
}
30
return result;
31
}
32
33
module.exports = pairs;
34
35