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.
Often used alongside List Length Changer, List Item Popper and List Length Finder.
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
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.