What Was New in ES2025 Iterator Helpers and Set Methods
ES2025 added iterator helpers, Set methods, Promise.try, RegExp.escape, regex modifiers, duplicate named groups and Float16Array. See each with real output.

ES2025 is the edition that finally gave JavaScript the standard-library pieces that every other language already had: lazy iteration helpers, the set algebra operations, a promise constructor that handles synchronous errors and a way to escape a string for a regular expression. None of them is exotic. Each replaces a small helper that projects keep copy-pasting, and each is available in Node.js 24 and current browsers, so you can use them today. This post goes through the features by how often they pay off, with the old way beside the new and real output from a run, and notes what changed on the way. Import attributes and JSON modules, also in this edition, have their own post. The previous edition is in what was new in ES2024, and the next in what is new in ES2026.
Iterator helpers
Iterators gain methods that mirror the array ones, and they work lazily, one item at a time, so they handle infinite sequences and large sources without building intermediate arrays.
function* naturals() {
let n = 1;
while (true) yield n++;
}
const result = naturals()
.filter((n) => n % 3 === 0)
.map((n) => n * n)
.drop(1)
.take(4)
.toArray();
console.log(result);
console.log(Iterator.from([5, 6, 7]).map((n) => n + 1).toArray());
console.log(new Set([1, 2, 3]).values().reduce((sum, n) => sum + n, 0));
console.log([10, 20, 30].values().some((n) => n > 25), [10, 20].values().every((n) => n > 15));
console.log(naturals().find((n) => n * n > 200));
console.log([[1, 2], [3]].values().flatMap((list) => list).toArray());
const seen = [];
naturals().take(3).forEach((n) => seen.push(n));
console.log(seen);
const lazy = naturals().map((n) => {
seen.push("computed " + n);
return n;
});
console.log(seen.length, lazy.next().value, seen.at(-1));[ 36, 81, 144, 225 ]
[ 6, 7, 8 ]
6
true false
15
[ 1, 2, 3 ]
[ 1, 2, 3 ]
3 1 computed 1The first pipeline filtered, squared, skipped one and took four values from an infinite generator, and stopped after four. Iterator.from() wraps any iterable or iterator-like object in the helper methods. The consuming methods, reduce, some, every, find, forEach and toArray, run the pipeline, and the last example shows the laziness: building the map computed nothing until next() asked. The old route was an array method chain, which builds a full array at every step, as in the post on flatMap(), or hand-written generators like those in the post on iterators.
Set methods
Sets gain the standard operations. Each takes a set-like argument, an object with size, has and keys, so a Map works too.
const frontend = new Set(["js", "css", "html"]);
const backend = new Set(["js", "sql", "node"]);
console.log(frontend.union(backend));
console.log(frontend.intersection(backend));
console.log(frontend.difference(backend));
console.log(frontend.symmetricDifference(backend));
console.log(new Set(["js"]).isSubsetOf(frontend));
console.log(frontend.isSupersetOf(new Set(["css", "html"])));
console.log(frontend.isDisjointFrom(new Set(["sql"])));
const roles = new Map([["admin", 1], ["editor", 2]]);
console.log(new Set(["admin", "viewer"]).intersection(roles));
const legacy = new Set([...frontend].filter((item) => backend.has(item)));
console.log(legacy);Set(5) { 'js', 'css', 'html', 'sql', 'node' }
Set(1) { 'js' }
Set(2) { 'css', 'html' }
Set(4) { 'css', 'html', 'sql', 'node' }
true
true
true
Set(1) { 'admin' }
Set(1) { 'js' }The four operations return new sets, in an order that follows the first set and then the second, and leave the inputs unchanged. The three predicates return booleans. A Map passed as an argument is treated as a set of its keys. The older spelling filters one spread array against the other set, as the last line shows, and it is both longer and easy to get wrong when the sets are large. The post on Sets and Maps shows where each structure fits.
Promise.try
new Promise((resolve) => resolve(fn())) and Promise.resolve().then(fn) were the two ways to start a promise chain from a function that might throw synchronously, and they differ in timing. Promise.try() runs the function immediately and turns a throw into a rejection.
function mayThrow(flag) {
if (flag === "throw") throw new Error("sync failure");
if (flag === "async") return Promise.resolve("async value");
return "plain value";
}
const log = [];
const results = await Promise.all(
["plain", "async", "throw"].map((flag) =>
Promise.try(mayThrow, flag).then(
(value) => value,
(error) => "caught: " + error.message,
),
),
);
console.log(results);
Promise.try(() => log.push("ran synchronously"));
log.push("after call");
console.log(log);
const viaThen = Promise.resolve().then(() => log.push("deferred by then"));
log.push("after then call");
await viaThen;
console.log(log);[ 'plain value', 'async value', 'caught: sync failure' ]
[ 'ran synchronously', 'after call' ]
[
'ran synchronously',
'after call',
'after then call',
'deferred by then'
]The same function returned a plain value, a promise and a throw, and all three came back as promises that could be handled in one then and catch. The callback ran synchronously, before the next line, which is the difference from Promise.resolve().then(fn), whose callback is deferred. Extra arguments after the function are passed to it, as flag was above. The post on try, catch and finally covers why a synchronous throw and a rejection need one path.
RegExp.escape
Embedding user input in a pattern needs escaping, and the language now provides it.
const query = "price (USD) [net]";
console.log(RegExp.escape("a.b*c"));
console.log(RegExp.escape("1+1=2"));
const pattern = new RegExp(RegExp.escape(query));
console.log(pattern.test("the price (USD) [net] is 5"), pattern.test("price USD net"));
const words = ["c++", "a.b", "x|y"];
const alternation = new RegExp(words.map(RegExp.escape).join("|"), "g");
console.log("use c++ or a.b or x|y".match(alternation));\x61\.b\*c
\x31\+1\x3d2
true false
[ 'c++', 'a.b', 'x|y' ]The special characters of the pattern language were escaped, and the escaped query matched the literal text and nothing else. A leading letter or digit is written as a hex escape so that it cannot merge with a preceding escape, which makes the output look odd and behave correctly. Building an alternation from a list of words, as in the last example, is the common case.
Regex modifiers and duplicate named groups
A modifier group applies a flag to part of a pattern, and a group name may repeat if the occurrences are in different alternatives.
console.log(/(?i:hello) World/.test("HELLO World"), /(?i:hello) World/.test("HELLO world"));
console.log(/a(?-i:b)c/i.test("ABC"), /a(?-i:b)c/i.test("AbC"));
const date = /(?<year>\d{4})-\d{2}-\d{2}|\d{2}\/\d{2}\/(?<year>\d{4})/;
console.log("2026-05-06".match(date).groups.year);
console.log("06/05/2026".match(date).groups.year);
const multiline = /^(?m:b)$/;
console.log(multiline.test("b"));true false
false true
2026
2026
trueThe first pattern ignored case only inside the group, and the second turned it back off inside a pattern that was case-insensitive overall. Both let one pattern mix case rules, which before needed two patterns. The date pattern reads a year in two formats under one group name, so the code that uses groups.year does not need to know which alternative matched. The m modifier works the same way, though in a single-line test it changes nothing.
Float16Array
Half-precision floats are 16 bits wide, which halves the memory of a 32-bit array and matches the formats used by graphics hardware and machine learning libraries.
const half = new Float16Array([0.1, 1.5, 65504, 70000, 1e-8]);
console.log(half);
console.log(Math.f16round(0.1), Math.f16round(1 / 3), Math.fround(0.1));
console.log(Float16Array.BYTES_PER_ELEMENT, half.byteLength);
const view = new DataView(new ArrayBuffer(4));
view.setFloat16(0, 1.5);
console.log(view.getFloat16(0), view.getUint8(0).toString(16), view.getUint8(1).toString(16));Float16Array(5) [ 0.0999755859375, 1.5, 65504, Infinity, 0 ]
0.0999755859375 0.333251953125 0.10000000149011612
2 10
1.5 3e 0Values were rounded to the nearest representable half float: 0.1 came back as 0.0999755859375, and 70000, above the largest finite value of 65504, became Infinity, while the tiny 1e-8 became 0, because it is below the smallest half-precision value. The range and precision are far smaller than a double's, so use half floats for large arrays where the memory matters and the precision does not. DataView has matching getFloat16 and setFloat16 methods for binary formats.
What else is in the edition
Besides the list above, the edition standardized JSON modules with import attributes, covered in its own post, and made Iterator a global with a constructor so that your own iterator classes can extend it and inherit the helpers. It also tidied several details in existing features that show up only in edge cases. The full list is in the specification's annex of changes, and the proposals repository's finished-proposals file links each one to its edition.
Trying them in a project
Adoption is mostly search and replace. Find the helpers that exist only to fill these gaps: a unique() that spreads a set, an intersect(a, b) that filters one array against the other, a deferred() that captures resolvers, an escapeRegExp() copied from a snippet. Replace each with the built-in, delete the helper and run the tests. For iterator helpers, the safe first step is converting a long filter().map().slice() chain over a large array into a lazy pipeline, and confirming with a test that the output is unchanged. Resist converting small chains: the array form is clearer for a dozen items and the gain is invisible.
Where to be careful
Support is the question, as always. Iterator helpers and set methods need Node.js 22, Promise.try and RegExp.escape need Node.js 24, and the browser versions vary, so check a compatibility table before relying on a feature in client code. Lazy helpers also change error timing: an exception thrown inside a map callback appears when the pipeline is consumed, not where it was defined, so keep callbacks pure and consume the pipeline soon. And a set method called on a set-like object with an inconsistent size and has can give odd results, so pass real sets or maps.
The features are defined in the ECMAScript 2025 specification, and MDN's pages on Iterator and Set list every method with its support.


