diff --git a/lib/internal/util/comparisons.js b/lib/internal/util/comparisons.js index 0596bd8b2a8b57..fc92579cebf3d4 100644 --- a/lib/internal/util/comparisons.js +++ b/lib/internal/util/comparisons.js @@ -543,11 +543,10 @@ function objEquiv(a, b, strict, keys, memos, iterationType) { } else { // Array is sparse. const keysA = objectKeys(a); - i++; for (; i < keysA.length; i++) { const key = keysA[i]; if (!hasOwnProperty(b, key) || - !innerDeepEqual(a[key], b[i], strict, memos)) { + !innerDeepEqual(a[key], b[key], strict, memos)) { return false; } } diff --git a/test/parallel/test-assert-deep.js b/test/parallel/test-assert-deep.js index 36758682941046..8c5620f183565a 100644 --- a/test/parallel/test-assert-deep.js +++ b/test/parallel/test-assert-deep.js @@ -557,9 +557,20 @@ assertNotDeepOrStrict( assertDeepAndStrictEqual(m3, m4); } -// Handle sparse arrays -assertDeepAndStrictEqual([1, , , 3], [1, , , 3]); -assertOnlyDeepEqual([1, , , 3], [1, , , 3, , , ]); +// Handle sparse arrays. +{ + assertDeepAndStrictEqual([1, , , 3], [1, , , 3]); + assertOnlyDeepEqual([1, , , 3], [1, , , 3, , , ]); + const a = new Array(3); + const b = new Array(3); + a[2] = true; + b[1] = true; + assertNotDeepOrStrict(a, b); + b[2] = true; + assertNotDeepOrStrict(a, b); + a[0] = true; + assertNotDeepOrStrict(a, b); +} // Handle different error messages {