DEV Community

Discussion on: `at` coming soon to ECMAScript

Collapse
 
fjones profile image
FJones

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.

 
dsm637 profile image
Denis Mitropolsky

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".

 
ashleyo profile image
Ashley Oliver

You would implement a stack as an object? Trippy ...