Skip to content

Commit e314e80

Browse files
authoredJul 18, 2023
Fix handling of sparse arrays (#110)
1 parent b58cb21 commit e314e80

File tree

3 files changed

+4
-5
lines changed

3 files changed

+4
-5
lines changed
 

Diff for: ‎index.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -295,12 +295,12 @@ export function escapePath(path) {
295295

296296
// The keys returned by Object.entries() for arrays are strings
297297
function entries(value) {
298+
const result = Object.entries(value);
298299
if (Array.isArray(value)) {
299-
// We use `[...value]` to convert sparse entries to normal ones.
300-
return [...value].map((value, index) => [index, value]);
300+
return result.map(([key, value]) => [Number(key), value]);
301301
}
302302

303-
return Object.entries(value);
303+
return result;
304304
}
305305

306306
function stringifyPath(pathSegments) {

Diff for: ‎readme.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ for (const property of deepKeys(user)) {
135135
}
136136
```
137137

138-
Sparse arrays are supported, but holes are filled. In general, [avoid using sparse arrays](https://github.com/sindresorhus/dot-prop/issues/109#issuecomment-1614819869).
138+
Sparse arrays are supported. In general, [avoid using sparse arrays](https://github.com/sindresorhus/dot-prop/issues/109#issuecomment-1614819869).
139139

140140
#### object
141141

Diff for: ‎test.js

-1
Original file line numberDiff line numberDiff line change
@@ -473,7 +473,6 @@ test('deepKeys - does not throw on sparse array', t => {
473473

474474
t.deepEqual(keys, [
475475
'sparse[0]',
476-
'sparse[1]',
477476
'sparse[2]',
478477
]);
479478
});

0 commit comments

Comments
 (0)
Please sign in to comment.