Well then... What is? The only benefits over indices seem to be that it throws on non-array and that you can use valid negative indices.
For negative indices, the main purpose is most definitely .at(-1), since anything dynamic still requires knowing the .length, and anything less than -1 implies a data structure that should probably be an object in the first place.
And if I want to throw on non-array, I'll just use TypeScript.
Well then... What is? The only benefits over indices seem to be that it throws on non-array and that you can use valid negative indices.
For negative indices, the main purpose is most definitely
.at(-1)
, since anything dynamic still requires knowing the.length
, and anything less than-1
implies a data structure that should probably be an object in the first place.And if I want to throw on non-array, I'll just use TypeScript.
Throws on non-array seems to me a real reason for using "at". TypeScript is not everywhere yet and even it is, there's still "any".
You would implement a stack as an object? Trippy ...