diff --git a/src/get-path.js b/src/get-path.js index 3097f60..a5d10c6 100644 --- a/src/get-path.js +++ b/src/get-path.js @@ -8,15 +8,15 @@ */ export default function getPath(object, path) { const segments = path.split('.'); - + /** @type {any} */ + let current = object; + /** @type {string|undefined} */ let segment; while ((segment = segments.shift())) { - if (!(segment in object)) { + if (!current || !(segment in current)) { return; } - object = object[segment]; + current = object[segment]; } - - return object; }