From c2b1d61dd1da466c750b6b30575c05e5f475bab3 Mon Sep 17 00:00:00 2001 From: jdalton Date: Sat, 16 May 2015 22:46:43 -0700 Subject: [PATCH] Add `toObject` to `_.pairs`. --- lodash.src.js | 2 ++ test/test.js | 6 ++++++ 2 files changed, 8 insertions(+) diff --git a/lodash.src.js b/lodash.src.js index 9aba6844a..48671c5a1 100644 --- a/lodash.src.js +++ b/lodash.src.js @@ -10000,6 +10000,8 @@ * // => [['barney', 36], ['fred', 40]] (iteration order is not guaranteed) */ function pairs(object) { + object = toObject(object); + var index = -1, props = keys(object), length = props.length, diff --git a/test/test.js b/test/test.js index ffd838b51..82f4a8edf 100644 --- a/test/test.js +++ b/test/test.js @@ -11813,6 +11813,12 @@ var object = { '0': 'a', '1': 'b', 'length': 2 }; deepEqual(_.pairs(object), [['0', 'a'], ['1', 'b'], ['length', 2]]); }); + + test('should work with strings', 2, function() { + _.each(['xo', Object('xo')], function(string) { + deepEqual(_.pairs(string), [['0', 'x'], ['1', 'o']]); + }); + }); }()); /*--------------------------------------------------------------------------*/