Menu

1 / 2

Native Iterator Helpers Just Shipped. Here's What You Stop Doing

DEV Community·Gabriel Anhaia·6 months ago
#2ZAeG0WF
#typescript#javascript#webdev#node#iterator
Reading 0:00
15s threshold

Book: TypeScript Essentials — From Working Developer to Confident TS, Across Node, Bun, Deno, and the Browser

Also by me: The TypeScript Library — the 5-book collection

My project: Hermes IDE | GitHub — an IDE for developers who ship with Claude Code and other AI coding tools

Me: xgabriel.com | GitHub

You have a list of 50,000 users. You want the names of the first 10 active ones. You write the line you have written a hundred times:

const names = users . filter ( u => u . active ) . map ( u => u . name ) . slice ( 0 , 10 );

Enter fullscreen mode

Exit fullscreen mode

Three array allocations. filter walks all 50,000 entries and builds a new array of, say, 32,000 active users. map then walks those 32,000 and builds a new array of 32,000 names. slice keeps the first 10 and builds the final array. You needed 10 strings. You materialized about 64,000 of them on the way, and the chain visited roughly 82,000 elements to do it.

Until last year, that was the price of Array.prototype chaining.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.