diff --git a/lodash.src.js b/lodash.src.js index 5ef870596..40ce222ba 100644 --- a/lodash.src.js +++ b/lodash.src.js @@ -2259,11 +2259,11 @@ if (pathKey !== undefined && pathKey in object) { path = [pathKey]; } - var index = -1, + var index = 0, length = path.length; - while (object != null && ++index < length) { - object = toObject(object)[path[index]]; + while (object != null && index < length) { + object = toObject(object)[path[index++]]; } return (index && index == length) ? object : undefined; } diff --git a/test/test.js b/test/test.js index f48e03240..037b597d2 100644 --- a/test/test.js +++ b/test/test.js @@ -13660,6 +13660,14 @@ }); }); + test('`_.' + methodName + '` should be able to return `null` values', 2, function() { + var object = { 'a': { 'b': null } }; + + _.each(['a.b', ['a', 'b']], function(path) { + strictEqual(func(object, path), null); + }); + }); + test('`_.' + methodName + '` should follow `path` over non-plain objects', 4, function() { var object = { 'a': '' }, paths = ['constructor.prototype.a', ['constructor', 'prototype', 'a']];