The value to test.
true if x is an array and the number of its own enumerable keys
equals its length; otherwise false.
// true: empty array has 0 keys and length 0
isDenseArray([]); // true
// true: element explicitly set (even if undefined) counts as an entry
isDenseArray([undefined]); // true
// false: "hole" at index 0 -> keys.length (0) !== length (1)
isDenseArray(new Array(1)); // false
// false: extra enumerable property increases keys.length beyond length
const a = [1];
a.foo = 'bar';
isDenseArray(a); // false
Determine whether a value is a "dense" JavaScript array.
A dense array, for the purposes of this function, is an array that:
Array.isArrayequivalent), andlengthproperty.In practice this means:
new Array(n)or by leaving indices unset) are not dense.arr.foo = 1) are not dense.undefinedstill count as entries and do not make the array sparse.