List Truncator

Truncates a list down to just the first N items or the last N items, using a direction toggle, dropping everything else, useful for previewing, sampling, or trimming overflow from a list. A free online tool from Staaarter, right in your browser.

Runs locallyUpdated 2026-07-27

Overview

Introduction

Trimming a list down to just the first or last handful of items is a common quick operation, whether for a preview, a sample, or removing overflow entries.

List Truncator keeps only the first N or last N items of a list, dropping everything else, with a simple direction toggle.

What Is List Truncator?

This is a list-editing tool that reduces a list to a target count from one end or the other, discarding the rest.

It's the simpler, single-output sibling of List Item Popper, which returns the removed items too; Truncator only returns what's kept.

How List Truncator Works

The input is split into items using the chosen separator, and the requested count is capped at the list's actual length.

`Array.prototype.slice()` extracts either the first N items (direction: start) or the last N items (direction: end), which are then rejoined into the output text.

When To Use List Truncator

Use this to quickly preview or sample the beginning or end of a large list.

It's also handy for trimming an oversized list down to a maximum allowed count before feeding it into a downstream tool or system.

Features

Advantages

  • Simple single-output result, no need to think about a second "removed items" output.
  • Gracefully caps the count instead of erroring when it exceeds the list's length.
  • Works with any separator style.

Limitations

  • Only shrinks a list; use List Length Changer if you also need padding when the list is too short.
  • Doesn't return the dropped items, use List Item Popper if you need to see what was removed.

Examples

Keeping the first 2 items

Input

a, b, c, d (count: 2, direction: start)

Output

a, b

Only the first two items are kept; the rest are dropped.

Keeping the last 2 items

Input

a, b, c, d (count: 2, direction: end)

Output

c, d

Only the final two items are kept.

Best Practices & Notes

Best Practices

  • Use direction "start" for previewing the head of a list and "end" for previewing the tail.
  • If you also need the discarded items, use List Item Popper instead, it returns both halves.

Developer Notes

Uses `Array.prototype.slice(0, keepCount)` for the start direction and `Array.prototype.slice(length - keepCount)` for the end direction, with `keepCount = Math.min(count, items.length)`.

List Truncator Use Cases

  • Previewing just the first few rows of a large pasted dataset
  • Trimming a list down to a maximum allowed item count before import
  • Sampling the most recent entries from the end of a chronological list

Common Mistakes

  • Expecting an error when the count exceeds the list's length; instead the whole list is kept unchanged.
  • Using this when the removed items are actually needed afterward; List Item Popper is the right tool for that.

Tips

  • Combine with List Statistics Generator afterward to confirm the new item count matches what you expect.
  • Use List Length Changer instead if the same operation also needs to pad short lists up to a fixed size.

References

Frequently Asked Questions