@smashingconf question for @mathias:
const arr = [];
let i = length;
while (i--) arr[i] = whatever;
Does are therefore become a holy array and deopt?
-
-
Why can't `fill` always transition to non-holey? Is there a case where it would still leave holes in array?
-
It's possible, but not currently seen as worth it. Typed arrays are usually a better answer.
End of conversation
New conversation -
-
-
Array.from({ length: n }, (_, i) => i) Holey? It’s my goto ‘range’ method
-
Yes, that array would be marked as holey. See https://mths.be/v8ek .
End of conversation
New conversation -
-
-
How about a new factory method Array.create(len, initValue)?
-
The feeling is this isn't worth it vs just use a typed array
- 1 more reply
New conversation -
-
-
And what if I eval an expression that uses only [] and object/primitive references?
-
The only way to create a hole within an array literal itself is to repeat a comma: [1, 2, , 3] If you don’t do that, the array remains packed. Also, have you considered using `JSON.parse` instead of `eval`?
- 1 more reply
New conversation -
Loading seems to be taking a while.
Twitter may be over capacity or experiencing a momentary hiccup. Try again or visit Twitter Status for more information.
JavaScript, HTML, CSS, HTTP, performance, security, Bash, Unicode, i18n, macOS.
(We could change this in