Encodera

Thanks for reading!

Donate to the site — we work hard for you.

JavaScript reference

Set.prototype.intersection

Returns the values two sets have in common.

Available since: ES2025

Syntax

setA.intersection(setB)

Parameters

ParameterTypeDescription
setBSetThe second set.

Return value

SetA new Set with the values found in both sets.

Examples

Common skills:

const anna = new Set(['js', 'css', 'sql']);
const oleg = new Set(['js', 'php', 'sql']);
 
console.log([...anna.intersection(oleg)].join(', '));

Output:

js, sql

Notes

For arrays the same is done with a.filter((x) => b.includes(x)).

See also

In the tutorial

  • Map and Set — The Map and Set collections in JavaScript: a dictionary with keys of any type and a set of unique values.

Thanks for reading!

Donate to the site — we work hard for you.