Files
it-know-how/typescript/bits/15-array-slice-and-indexing.md
2026-03-27 12:58:01 +01:00

604 B
Executable File

Array slice and Indexing

Your snippet uses slice and index-based access to create weekly intervals.

slice(0, -1)

const periodStarts = alignedStarts.slice(0, -1);
  • Start at index 0.
  • Stop before the last item (-1 means from the end).
  • Useful when each start needs a following end item.

Index access

const end = alignedStarts[index + 1];
  • Gets the next boundary after the current start.

Python comparison

period_starts = aligned_starts[:-1]
end = aligned_starts[index + 1]

This is the same concept as Python slicing and list indexing.