Pythonic array slicing in JavaScript