A list of 'legal' JavaScript string/array indexes/slices?

A list of 'legal' JavaScript string/array indexes/slices?
0

#1

Hi,

I once put together a list of legal Python slices: for example -

variable[0]
variable[1:3]
variable[::-1]
variable[:]

And so on.

Is there something comparable in JS? I know we can access indexes such as array[2][1] and so on, but where can I get all the legal expressions? Obviously, the exact expression for something like Python’s variable[::-1] will be different in JS.

Specifically, I’d like to access ALL the elements/indices of an array or subarray. Is that possible without getting into .length expressions for arrays you might not know the length of?

Thank you.


#2

Generally, JavaScript code tends towards functional expressions like map, filter, and reduce rather than building loops, so I rarely get the length of an array at all. To get the exact functionality from Python’s (really cool) array syntax, you’d probably want Array.prototype.slice, but there’s no way to do it just with JavaScript’s array access syntax.