diff --git a/lib/object.js b/lib/object.js index ec00be4..7bd6daa 100644 --- a/lib/object.js +++ b/lib/object.js @@ -3,7 +3,8 @@ import { forEach } from './collection'; import { isObject, isUndefined, - isDefined + isDefined, + isNil } from './lang'; @@ -41,7 +42,7 @@ export function set(target, path, value) { var nextKey = path[idx + 1]; var nextTarget = currentTarget[key]; - if (isDefined(nextKey) && !nextTarget) { + if (isDefined(nextKey) && isNil(nextTarget)) { nextTarget = currentTarget[key] = isNaN(+nextKey) ? {} : []; } diff --git a/test/object.spec.js b/test/object.spec.js index fd0c178..745b90c 100644 --- a/test/object.spec.js +++ b/test/object.spec.js @@ -400,6 +400,16 @@ describe('object', function() { } } }); + + expect( + set({ a: null }, [ 'a', 'b', 'c' ], 'C') + ).to.eql({ + a: { + b: { + c: 'C' + } + } + }); });