codegurukool.com · Free coding tutorials & online compiler

Home › JavaScript Tutorial › JS sets

JS sets

Collections of unique values.

A Set ignores duplicates. Use add, has, delete and size. Spread it to get an array.

Example code

<p id='o'></p>
<script>
const s=new Set([1,2,2,3,3,3]);s.add(4);
o.textContent='Unique: '+[...s]+' size '+s.size+' has 2? '+s.has(2);
</script>

Run this code in the online editor

← JS arraysJS maps →