<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: PariSh KhAn</title>
    <description>The latest articles on DEV Community by PariSh KhAn (@parish).</description>
    <link>https://dev.to/parish</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F202612%2Ffa1b03f1-94ad-4428-90fc-8608bffd1f2f.jpeg</url>
      <title>DEV Community: PariSh KhAn</title>
      <link>https://dev.to/parish</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/parish"/>
    <language>en</language>
    <item>
      <title>How I Run Whisper and Export Captioned MP4s Entirely in the Browser</title>
      <dc:creator>PariSh KhAn</dc:creator>
      <pubDate>Sat, 14 Nov 2026 19:27:20 +0000</pubDate>
      <link>https://dev.to/parish/how-i-run-whisper-and-export-captioned-mp4s-entirely-in-the-browser-39d8</link>
      <guid>https://dev.to/parish/how-i-run-whisper-and-export-captioned-mp4s-entirely-in-the-browser-39d8</guid>
      <description>&lt;p&gt;Getting a transcript is only the first handoff in a caption editor. After that, the words have to survive several clocks, a live preview, a style system, and a video encoder.&lt;/p&gt;

&lt;p&gt;I’m building &lt;a href="https://karaokecaptions.com/?utm_source=devto&amp;amp;utm_medium=article&amp;amp;utm_campaign=browser_pipeline" rel="noopener noreferrer"&gt;Karaoke Captions&lt;/a&gt;, a React and TypeScript editor that transcribes and renders video locally. In an earlier post I gave an overview of the product. This time I want to walk through the implementation choices that make a word-by-word caption become a finished MP4.&lt;/p&gt;

&lt;p&gt;The interesting parts are the boundaries: compressed media to PCM, model output to editable timing, preview time to export time, and decoded frames to an MP4 container.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fgl2trei2kts9zov7lz66.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fgl2trei2kts9zov7lz66.png" alt="Karaoke Captions editor with a video preview, editable transcript and caption timeline" width="800" height="556"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  The pipeline I keep separate from the interface
&lt;/h2&gt;

&lt;p&gt;The local workflow has six main stages:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;File / Blob
  → decode audio to 16 kHz mono Float32 PCM
  → transcribe in a Web Worker
  → normalise word timestamps and build phrases
  → edit text, timing and style
  → draw captions over decoded video frames
  → encode and mux the finished MP4
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;React owns the editing interface. The document holds the words and style choices. The transcription worker handles model work. The rendering code decides what a caption looks like at a given time.&lt;/p&gt;

&lt;p&gt;That separation lets me revise a font or a sentence without running speech recognition again. It also gives the preview and export a shared description of the video they’re supposed to produce.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Get the audio contract right before asking Whisper anything
&lt;/h2&gt;

&lt;p&gt;A video file isn’t the audio representation the speech pipeline expects.&lt;/p&gt;

&lt;p&gt;My transcription path uses &lt;strong&gt;16 kHz, mono, Float32 PCM&lt;/strong&gt;. The input might arrive with a different sample rate, multiple channels, or an audio codec that needs another decoding path.&lt;/p&gt;

&lt;p&gt;I start with Web Audio decoding, downmix the channels, and resample. There’s also a streaming decoding fallback for inputs the first path can’t handle and for memory-constrained cases.&lt;/p&gt;

&lt;p&gt;The memory side is easy to underestimate. At 16,000 samples per second and four bytes per Float32 sample, ten minutes of the final mono PCM is about 38.4 MB in decimal units. That’s just one representation. The original video, a higher-rate decoded buffer, the model, and intermediate allocations can coexist.&lt;/p&gt;

&lt;p&gt;So I avoid copying a large ArrayBuffer simply to pass it into the next step, and I release references when the decoder no longer needs them. A small compressed file doesn’t imply a small decoded working set.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. A worker needs a useful protocol, not just a completion event
&lt;/h2&gt;

&lt;p&gt;I run Whisper through &lt;a href="https://huggingface.co/docs/transformers.js/en/index" rel="noopener noreferrer"&gt;Transformers.js&lt;/a&gt; in a Web Worker. The main thread receives progress, partial text, the selected execution device, completed words, or an error.&lt;/p&gt;

&lt;p&gt;Those are separate states because they describe separate work. Downloading a model isn’t the same as transcribing a clip. A worker that can only say “started” and “finished” gives the interface very little to explain.&lt;/p&gt;

&lt;p&gt;I also check for a usable GPU adapter rather than treating the existence of &lt;code&gt;navigator.gpu&lt;/code&gt; as proof that inference will run. My implementation has a WebAssembly path and retries in a fresh worker if WebGPU session initialisation fails.&lt;/p&gt;

&lt;p&gt;That last detail is specific to the runtime behaviour my app has to handle. I don’t want a failed acceleration attempt to be the end of the user’s captioning session.&lt;/p&gt;

&lt;p&gt;For longer audio, I segment the PCM around pauses, transcribe those segments, and add the segment’s offset back to each word timestamp. Otherwise, words from a later segment would be timed as though they occurred near the start of the video.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. Give each clock a name
&lt;/h2&gt;

&lt;p&gt;Model timestamps arrive in seconds. Phrase boundaries in my renderer use milliseconds. Remotion also has a frame clock.&lt;/p&gt;

&lt;p&gt;The conversions are small enough to look harmless:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;secToMs&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;seconds&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;number&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;round&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;seconds&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;1000&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;msToFrame&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;milliseconds&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;number&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;fps&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;number&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt;
  &lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;round&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;milliseconds&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="mi"&gt;1000&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;fps&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The important choice is where they live. I keep the conversion boundary explicit rather than scattering multiplications throughout the caption components.&lt;/p&gt;

&lt;p&gt;In the current export path, a decoded sample’s timestamp is in seconds. The drawing call converts it to the millisecond time the caption renderer expects. When working directly with raw WebCodecs objects, check their documented timestamp units too; the surrounding abstraction matters.&lt;/p&gt;

&lt;p&gt;I also normalise the words before grouping them: trim empty text, reject non-finite times, keep them chronological, and constrain implausible durations. A timestamp is model output, not a promise that the next stage can skip validation.&lt;/p&gt;

&lt;h2&gt;
  
  
  4. Phrase grouping is part of rendering correctness
&lt;/h2&gt;

&lt;p&gt;Grouping every three words is a reasonable starting point. Speech also contains punctuation and pauses.&lt;/p&gt;

&lt;p&gt;My grouping logic breaks at punctuation and longer pauses, bridges short gaps, and clears captions during longer gaps. More importantly, it clamps a phrase’s end against the next phrase’s start.&lt;/p&gt;

&lt;p&gt;The intended display interval is half-open:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;startMs &amp;lt;= currentTimeMs &amp;lt; endMs
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That gives adjacent captions an unambiguous handoff. If one path draws every matching phrase and another path chooses the first match, overlapping intervals can make preview and export disagree. Fixing the interval data removes that ambiguity before either renderer sees it.&lt;/p&gt;

&lt;p&gt;This is also why SRT import needs a clear timing model. A normal SRT cue supplies a caption window, not the exact delivery of every word. Imported caption times are preserved; word highlights are estimated inside them and remain editable.&lt;/p&gt;

&lt;h2&gt;
  
  
  5. Share the drawing code between preview and export
&lt;/h2&gt;

&lt;p&gt;I don’t want to maintain a browser-CSS version of a style and a separately interpreted export version.&lt;/p&gt;

&lt;p&gt;For the Pro looks, the preview, style thumbnails, and exported frames use the same canvas rendering engine. The renderer receives the style, phrase data, time, and dimensions, then draws that state.&lt;/p&gt;

&lt;p&gt;That makes a paused preview frame and an exported frame comparable. It also encourages deterministic animation: derive the look from the supplied timeline time, rather than &lt;code&gt;Date.now()&lt;/code&gt; or a new random value on every draw.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fqvw8lpi3ywo93ujcr894.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fqvw8lpi3ywo93ujcr894.png" alt="Karaoke Captions style gallery with Classic, Lyrics and additional looks" width="800" height="556"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;The gallery is another view of the rendering system, rather than a separate set of illustrative mockups.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Fonts are another dependency of the frame. If text is measured before the chosen font is ready, a later font load can change line breaks or alignment. I wait for the required fonts before relying on their layout.&lt;/p&gt;

&lt;h2&gt;
  
  
  6. Export decoded frames in sequence
&lt;/h2&gt;

&lt;p&gt;The current MP4 path uses &lt;a href="https://mediabunny.dev/" rel="noopener noreferrer"&gt;Mediabunny&lt;/a&gt; around browser media APIs. It reads the file, decodes video frames in order, draws the source frame and caption overlay onto a canvas, and encodes H.264 into an MP4 output.&lt;/p&gt;

&lt;p&gt;The drawing callback is conceptually:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sample timestamp
  → source video frame, with rotation and fit applied
  → motion graphics at that time
  → caption style and active word at that time
  → optional watermark
  → encoded output
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Reading frames in sequence avoids asking a hidden video element to seek independently for every output frame. I retain a seeking fallback for inputs the conversion path can’t handle, but it isn’t the preferred route.&lt;/p&gt;

&lt;p&gt;Audio deserves its own decision. In the conversion path, a compatible audio track can be copied into the output rather than unnecessarily decoded and encoded again. Container compatibility and the selected path determine what’s possible.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Web/API/WebCodecs_API" rel="noopener noreferrer"&gt;WebCodecs&lt;/a&gt; provides low-level audio and video codec interfaces. It doesn’t turn encoded chunks into a ready-to-download MP4 by itself; the container and muxing work still has to happen.&lt;/p&gt;

&lt;h2&gt;
  
  
  What the user should see at these boundaries
&lt;/h2&gt;

&lt;p&gt;A creator doesn’t need to learn any of this to caption a clip. They do need the interface to explain what the app is doing and what the downloaded file contains.&lt;/p&gt;

&lt;p&gt;That’s why I keep transcript review, &lt;strong&gt;Fix timing&lt;/strong&gt;, style selection, and output format visible in the workflow.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fcst8umdjcyair0t7xaz1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fcst8umdjcyair0t7xaz1.png" alt="Export dialog offering a captioned MP4 and separate SRT and VTT downloads" width="800" height="556"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;An MP4 includes the visible caption design. SRT and VTT contain timed text, so they’re useful for another editor or a separate subtitle track rather than carrying the animation.&lt;/p&gt;

&lt;p&gt;If you want to try the implementation as a product, &lt;a href="https://karaokecaptions.com/?utm_source=devto&amp;amp;utm_medium=article&amp;amp;utm_campaign=browser_pipeline&amp;amp;utm_content=closing_cta" rel="noopener noreferrer"&gt;Karaoke Captions&lt;/a&gt; has free, watermark-free Classic and Lyrics exports with no account. Extra Pro styles can be tried in the editor; their free MP4 exports have a small watermark. Desktop Chrome or Edge is the workflow I recommend for MP4 output.&lt;/p&gt;

&lt;p&gt;The part I keep coming back to is the handoff. A speech model, a preview, and an encoder can each work in isolation while disagreeing about the same second of video. Naming the units, sharing the renderer, and validating the timeline make those pieces behave like one editor.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>ai</category>
      <category>architecture</category>
    </item>
    <item>
      <title>I built a caption editor that keeps video processing in the browser</title>
      <dc:creator>PariSh KhAn</dc:creator>
      <pubDate>Mon, 09 Nov 2026 17:21:37 +0000</pubDate>
      <link>https://dev.to/parish/i-built-a-caption-editor-that-keeps-video-processing-in-the-browser-o63</link>
      <guid>https://dev.to/parish/i-built-a-caption-editor-that-keeps-video-processing-in-the-browser-o63</guid>
      <description>&lt;p&gt;I’m the maker of &lt;a href="https://karaokecaptions.com/" rel="noopener noreferrer"&gt;Karaoke Captions&lt;/a&gt;, a browser editor for animated, word-by-word video captions. Its main design constraint is simple: the source video stays on your device for transcription and rendering.&lt;/p&gt;

&lt;p&gt;Here is the workflow and the browser technology behind it.&lt;/p&gt;

&lt;h2&gt;
  
  
  From a clip to a captioned MP4
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Open the editor and select a video.&lt;/li&gt;
&lt;li&gt;Generate a transcript locally, or import an existing SRT file.&lt;/li&gt;
&lt;li&gt;Review the words and timing, then choose and adjust a caption style.&lt;/li&gt;
&lt;li&gt;Export a captioned MP4, or download SRT/VTT subtitles.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;There are &lt;strong&gt;100+ caption styles, and I continue to expand the library&lt;/strong&gt;. You can &lt;a href="https://karaokecaptions.com/caption-styles/" rel="noopener noreferrer"&gt;browse the styles&lt;/a&gt; before opening the editor.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fdc1zfvnpswk2vf2zsuq4.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fdc1zfvnpswk2vf2zsuq4.png" alt="Examples of animated caption styles in Karaoke Captions" width="800" height="420"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  What runs locally
&lt;/h2&gt;

&lt;p&gt;The editing interface uses React and TypeScript, with Remotion Player for the live preview. Speech recognition uses Whisper through Transformers.js in a Web Worker, with WebGPU or WebAssembly depending on the available execution path. MP4 export uses WebCodecs.&lt;/p&gt;

&lt;p&gt;That division lets the interface remain interactive while transcription work runs separately. It also means there is no server-side video upload step for the local transcription and rendering workflow. The browser still needs to download the application and speech model initially; “on device” does not mean the first visit needs no network connection.&lt;/p&gt;

&lt;p&gt;Once the app and model have loaded, the local captioning workflow can work offline. This is particularly useful when a clip should stay on the creator’s machine.&lt;/p&gt;

&lt;h2&gt;
  
  
  The tradeoffs
&lt;/h2&gt;

&lt;p&gt;Moving work into the browser moves its hardware requirements there too. Transcription and export speed depend on the device, browser support and clip. I recommend desktop Chrome or Edge for MP4 export. I’m not claiming a universal speed advantage over hosted transcription.&lt;/p&gt;

&lt;p&gt;The initial model download is another visible cost. A hosted tool can hide model setup behind its servers; a local tool asks the user’s device to do that setup. That tradeoff needs to be clear before someone starts.&lt;/p&gt;

&lt;p&gt;Recognition also needs a human review. Names, background noise and overlapping speech can produce mistakes. Being able to edit the transcript and timing is part of the workflow, not an optional final polish.&lt;/p&gt;

&lt;h2&gt;
  
  
  Free and paid features
&lt;/h2&gt;

&lt;p&gt;Classic and Lyrics styles support unlimited watermark-free MP4/SRT/VTT exports without an account. Other styles and creative tools are available to try; free exports using Pro features can have a small watermark, and Pro removes it. The app is proprietary and freemium.&lt;/p&gt;

&lt;p&gt;If you build browser media tools, I’d be interested in your experience with model-download UX and device limits. If you make videos, does keeping your clips local make the initial download worthwhile?&lt;/p&gt;

&lt;p&gt;&lt;a href="https://karaokecaptions.com/" rel="noopener noreferrer"&gt;Try Karaoke Captions&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>showdev</category>
      <category>webdev</category>
    </item>
    <item>
      <title>JavaScript Set Explained Like You're 10</title>
      <dc:creator>PariSh KhAn</dc:creator>
      <pubDate>Thu, 23 Jul 2026 17:02:13 +0000</pubDate>
      <link>https://dev.to/parish/javascript-set-explained-like-youre-10-1n3m</link>
      <guid>https://dev.to/parish/javascript-set-explained-like-youre-10-1n3m</guid>
      <description>&lt;p&gt;If you have used Python before, you probably already know about &lt;code&gt;set&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;When I started using JavaScript &lt;code&gt;Set&lt;/code&gt;, I immediately thought:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;"Finally! I always wished JavaScript had this."&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;It solves a very common problem with just one line of code.&lt;/p&gt;

&lt;p&gt;Let's learn it with simple examples.&lt;/p&gt;




&lt;h1&gt;
  
  
  Imagine a Toy Box
&lt;/h1&gt;

&lt;p&gt;You have a toy box.&lt;/p&gt;

&lt;p&gt;Every time you put a toy inside, your mom checks one thing.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Is this toy already in the box?&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;If &lt;strong&gt;no&lt;/strong&gt;, she puts it in.&lt;/li&gt;
&lt;li&gt;If &lt;strong&gt;yes&lt;/strong&gt;, she ignores it.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;That is exactly how a JavaScript &lt;code&gt;Set&lt;/code&gt; works.&lt;/p&gt;

&lt;p&gt;A &lt;code&gt;Set&lt;/code&gt; only stores &lt;strong&gt;unique values&lt;/strong&gt;.&lt;/p&gt;




&lt;h1&gt;
  
  
  Creating Your First Set
&lt;/h1&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;toys&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Set&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now let's add some toys.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;toys&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Car&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;toys&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Robot&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;toys&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Car&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now print it.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;toys&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Set(2) { 'Car', 'Robot' }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Even though we added &lt;code&gt;"Car"&lt;/code&gt; twice, it only appears once.&lt;/p&gt;

&lt;p&gt;That is the magic of &lt;code&gt;Set&lt;/code&gt;.&lt;/p&gt;




&lt;h1&gt;
  
  
  Arrays Can Have Duplicates
&lt;/h1&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;fruits&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
  &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Apple&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Apple&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Orange&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Banana&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Banana&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
&lt;span class="p"&gt;];&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Apple
Apple
Orange
Banana
Banana
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Sometimes this is what you want.&lt;/p&gt;

&lt;p&gt;Sometimes it isn't.&lt;/p&gt;




&lt;h1&gt;
  
  
  Remove Duplicates Instantly
&lt;/h1&gt;

&lt;p&gt;With &lt;code&gt;Set&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;fruits&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
  &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Apple&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Apple&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Orange&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Banana&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Banana&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
&lt;span class="p"&gt;];&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;uniqueFruits&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Set&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;fruits&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;uniqueFruits&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Set(3) {
  'Apple',
  'Orange',
  'Banana'
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Only unique values remain.&lt;/p&gt;




&lt;h1&gt;
  
  
  Convert It Back to an Array
&lt;/h1&gt;

&lt;p&gt;Most of the time you still want an array.&lt;/p&gt;

&lt;p&gt;Easy.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;uniqueFruits&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[...&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Set&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;fruits&lt;/span&gt;&lt;span class="p"&gt;)];&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;uniqueFruits&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="p"&gt;[&lt;/span&gt;
  &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Apple&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Orange&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Banana&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
&lt;span class="p"&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is probably the most common use of &lt;code&gt;Set&lt;/code&gt;.&lt;/p&gt;




&lt;h1&gt;
  
  
  Check If Something Exists
&lt;/h1&gt;

&lt;p&gt;Instead of writing:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;fruits&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;includes&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Apple&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can do:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;fruits&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Set&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;
  &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Apple&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Orange&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Banana&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
&lt;span class="p"&gt;]);&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;fruits&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;has&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Apple&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;true
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It reads very naturally.&lt;/p&gt;




&lt;h1&gt;
  
  
  Remove Something
&lt;/h1&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;fruits&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;delete&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Orange&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now the set contains:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Apple
Banana
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h1&gt;
  
  
  Remove Everything
&lt;/h1&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;fruits&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;clear&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now the set is empty.&lt;/p&gt;




&lt;h1&gt;
  
  
  Count Items
&lt;/h1&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;fruits&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;size&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;3
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Notice something?&lt;/p&gt;

&lt;p&gt;Arrays use:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;array&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Sets use:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;set&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;size&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h1&gt;
  
  
  Loop Through a Set
&lt;/h1&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;colors&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Set&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;
  &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Red&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Blue&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Green&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
&lt;span class="p"&gt;]);&lt;/span&gt;

&lt;span class="k"&gt;for &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;color&lt;/span&gt; &lt;span class="k"&gt;of&lt;/span&gt; &lt;span class="nx"&gt;colors&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;color&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Red
Blue
Green
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h1&gt;
  
  
  A Real-Life Example
&lt;/h1&gt;

&lt;p&gt;Imagine users enter email addresses.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;emails&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
  &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;john@gmail.com&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;john@gmail.com&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;mary@gmail.com&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;john@gmail.com&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;alice@gmail.com&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
&lt;span class="p"&gt;];&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You only want unique emails.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;uniqueEmails&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[...&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Set&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;emails&lt;/span&gt;&lt;span class="p"&gt;)];&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Result:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="p"&gt;[&lt;/span&gt;
  &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;john@gmail.com&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;mary@gmail.com&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;alice@gmail.com&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
&lt;span class="p"&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Done.&lt;/p&gt;

&lt;p&gt;No complicated loops.&lt;/p&gt;

&lt;p&gt;No extra code.&lt;/p&gt;




&lt;h1&gt;
  
  
  When Should You Use Set?
&lt;/h1&gt;

&lt;p&gt;&lt;code&gt;Set&lt;/code&gt; is great when you need:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Remove duplicate values&lt;/li&gt;
&lt;li&gt;Keep only unique items&lt;/li&gt;
&lt;li&gt;Check whether something already exists&lt;/li&gt;
&lt;li&gt;Store unique IDs&lt;/li&gt;
&lt;li&gt;Store tags&lt;/li&gt;
&lt;li&gt;Store usernames&lt;/li&gt;
&lt;li&gt;Store email addresses&lt;/li&gt;
&lt;/ul&gt;




&lt;h1&gt;
  
  
  When Should You Use an Array Instead?
&lt;/h1&gt;

&lt;p&gt;Use an array if:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Duplicates matter&lt;/li&gt;
&lt;li&gt;You need indexes&lt;/li&gt;
&lt;li&gt;You need sorting or mapping&lt;/li&gt;
&lt;li&gt;You care about item order and array methods&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Arrays and Sets solve different problems.&lt;/p&gt;




&lt;h1&gt;
  
  
  Final Thoughts
&lt;/h1&gt;

&lt;p&gt;&lt;code&gt;Set&lt;/code&gt; is one of those JavaScript features that makes your code cleaner and easier to read.&lt;/p&gt;

&lt;p&gt;If you come from Python, it will probably feel familiar.&lt;/p&gt;

&lt;p&gt;If you're new to programming, think of it as a smart collection that automatically says:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;"I already have this. I don't need another one."&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Sometimes the simplest tools become your favorites.&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>javascript</category>
      <category>tutorial</category>
    </item>
  </channel>
</rss>
