Skip to content

Commit

Permalink
fix deepkeys for sparsed arrays
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Kostyukov committed Jul 4, 2023
1 parent b58cb21 commit d638cf8
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 3 deletions.
3 changes: 1 addition & 2 deletions index.js
Expand Up @@ -296,8 +296,7 @@ export function escapePath(path) {
// The keys returned by Object.entries() for arrays are strings
function entries(value) {
if (Array.isArray(value)) {
// We use `[...value]` to convert sparse entries to normal ones.
return [...value].map((value, index) => [index, value]);
return Object.entries(value).map(([key, value]) => [Number(key), value]);
}

return Object.entries(value);
Expand Down
1 change: 0 additions & 1 deletion test.js
Expand Up @@ -473,7 +473,6 @@ test('deepKeys - does not throw on sparse array', t => {

t.deepEqual(keys, [
'sparse[0]',
'sparse[1]',
'sparse[2]',
]);
});
Expand Down

0 comments on commit d638cf8

Please sign in to comment.