diff --git a/index.js b/index.js index e6a107f..acc3a53 100644 --- a/index.js +++ b/index.js @@ -295,12 +295,12 @@ export function escapePath(path) { // The keys returned by Object.entries() for arrays are strings function entries(value) { + const result = Object.entries(value); if (Array.isArray(value)) { - // We use `[...value]` to convert sparse entries to normal ones. - return [...value].map((value, index) => [index, value]); + return result.map(([key, value]) => [Number(key), value]); } - return Object.entries(value); + return result; } function stringifyPath(pathSegments) { diff --git a/readme.md b/readme.md index 5c7adf2..ebdc035 100644 --- a/readme.md +++ b/readme.md @@ -135,7 +135,7 @@ for (const property of deepKeys(user)) { } ``` -Sparse arrays are supported, but holes are filled. In general, [avoid using sparse arrays](https://github.com/sindresorhus/dot-prop/issues/109#issuecomment-1614819869). +Sparse arrays are supported. In general, [avoid using sparse arrays](https://github.com/sindresorhus/dot-prop/issues/109#issuecomment-1614819869). #### object diff --git a/test.js b/test.js index 39655d7..b8415c1 100644 --- a/test.js +++ b/test.js @@ -473,7 +473,6 @@ test('deepKeys - does not throw on sparse array', t => { t.deepEqual(keys, [ 'sparse[0]', - 'sparse[1]', 'sparse[2]', ]); });