{"id":19302,"date":"2020-07-10T16:17:43","date_gmt":"2020-07-10T23:17:43","guid":{"rendered":"https:\/\/careerkarma.com\/blog\/?p=19302"},"modified":"2023-12-01T03:54:15","modified_gmt":"2023-12-01T11:54:15","slug":"javascript-set","status":"publish","type":"post","link":"https:\/\/careerkarma.com\/blog\/javascript-set\/","title":{"rendered":"JavaScript Set: A Guide for Beginners"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">How to Use Sets in JavaScript <\/h2>\n\n\n\n<p>Do you have a list of data that should only contain unique values? This is where the JavaScript Set data type really shines. It&#8217;s a new type of object that allows you to create a collection of unique values; no duplicates are allowed within a set.<br><\/p>\n\n\n\n<p>In this guide, we&#8217;re going to talk about what sets are, how they work, and when they can be useful. We&#8217;ll walk through a few examples of each of the Set methods available in JavaScript.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">What Is a Set?<\/h2>\n\n\n\n<p>A Set is a set of values that cannot contain duplicates. This data type was introduced in ECMAScript 6. Notably, Sets are a feature of many other programming languages.<br><\/p>\n\n\n\n<p>Lists are useful because they allow you to store multiple values. Lists support storing duplicate values, which can be useful in a myriad of scenarios.<br><\/p>\n\n\n\n<p>For instance, if you&#8217;re storing a list of orders made at a coffee shop, you&#8217;ll need to be able to store duplicate values. Two customers may order the same drink.<br><\/p>\n\n\n\n<p>There are some instances where you&#8217;ll want to store only unique values in a list. That&#8217;s where you&#8217;d want to use the Set object. Values in Sets can only appear once.<br><\/p>\n\n\n\n<p>In JavaScript, a set is declared like any other object. Let&#8217;s create a Set which stores a list of the favorite cakes reported by customers at a local tea room:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>let cakes = new Set();\nconsole.log(cakes)<\/pre><\/div>\n\n\n\n<p>Our code returns: <code>Set []<\/code>. We&#8217;ve just created a Set. It has no values at the moment, as you can see from the output of our code; we&#8217;ll add those in next.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Initialize a Set with Default Values<\/h2>\n\n\n\n<p>Sets can be initialized from an array, string, or another iterable. This is useful because it means that you don&#8217;t have to add values manually to your Set; you can work from existing ones.<br><\/p>\n\n\n\n<p>Consider the following list:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>let cake_list = [\"Lemon Cake\", \"Carrot Cake\", \"Strawberry Cheesecake\"];<\/pre><\/div>\n\n\n\n<p>These values are currently stored in an array. To convert them into a Set, we can pass our array when we create a new Set object:<br><\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>let cakes = new Set(cake_list);\nconsole.log(cakes)<\/pre><\/div>\n\n\n\n<p>Our code returns:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>Set(3) [\"Lemon Cake\", \"Carrot Cake\", \"Strawberry Cheesecake\"]<\/pre><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">Adding Values to a Set<\/h2>\n\n\n\n<p>The Set object comes with a method called <code>add()<\/code> which makes it easy to add items into a set. The name of the method used to add an item to a set is even easy to remember: <code>add()<\/code>.<br><\/p>\n\n\n\n<p>Let&#8217;s say that we want to add &#8220;Boston Cream Pie&#8221; to our list of cakes that are being sold at a local bakery. Let&#8217;s use the <code>add()<\/code> method to add this value:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>cakes.add(\"Boston Cream Pie\");\nconsole.log(cakes);<\/pre><\/div>\n\n\n\n<p>Our code returns:<br><\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>Set(4) [\"Lemon Cake\", \"Carrot Cake\", \"Strawberry Cheesecake\", \"Boston Cream Pie\"]<\/pre><\/div>\n\n\n\n<p>Our Set now contains four objects. If you try to add an item that is already in a Set, that item will not be added. Sets cannot store duplicate values.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Checking if a Value Exists in a Set<\/h2>\n\n\n\n<p>We need to check whether or not &#8220;Boston Cream Pie&#8221; is on our list of cakes. It was a new addition to the list of cakes and the baker wants to double-check we have added it.<br><\/p>\n\n\n\n<p>That&#8217;s where the <code>has()<\/code> method comes in. The <code>has()<\/code> method allows you to check to see whether a Set <em>has<\/em> a particular value. Again, the method has a name that&#8217;s easy to remember!<br><\/p>\n\n\n\n<p>Consider the following code:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>var has_boston_cream_pie = cakes.has(\"Boston Cream Pie\");\nconsole.log(has_boston_cream_pie);<\/pre><\/div>\n\n\n\n<p>Our code returns: <code>true<\/code>. The <code>has()<\/code> method returns a boolean value\u2014either true or false\u2014depending on whether a Set contains a particular value. This method is similar to <code>includes()<\/code> that you&#8217;d use on an array but <code>has()<\/code> only works with Sets.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Removing a Value from a Set<\/h2>\n\n\n\n<p>The baker has decided that strawberry cheesecakes will no longer be served at the bakery. The strawberry cheesecake took longer to make than other cakes and was not very popular.<br><\/p>\n\n\n\n<p>You can remove a value from a Set using the aptly-named <code>delete()<\/code> method. Let&#8217;s remove the value &#8220;Strawberry Cheesecake&#8221; from our Set:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>cakes.delete(\"Strawberry Cheesecake\");\nconsole.log(cakes);<\/pre><\/div>\n\n\n\n<p>Our code returns:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>Set(3) [\"Lemon Cake\", \"Carrot Cake\", \"Boston Cream Pie\"]<\/pre><\/div>\n\n\n\n<p>Strawberry cheesecake was removed from our Set.<br><\/p>\n\n\n\n<p>You can remove all the values from a Set using the <code>clear()<\/code> method.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Iterate Over a Set<\/h2>\n\n\n\n<p>Sets, like lists, are iterable objects. You know what that means: you can iterate over them.&nbsp;<br><\/p>\n\n\n\n<p>We&#8217;re going to use a for-each loop to iterate over our cakes set. Our for-each loop will go through every item in our list\u2014for each item in the list\u2014and print it to the console:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>cakes.forEach(cake =&gt; {\n\tconsole.log(cake);\n}<\/pre><\/div>\n\n\n\n<p>Our code returns an iterator which prints out each value in our Set to the console:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>Lemon Cake\nCarrot Cake\nBoston Cream Pie<\/pre><\/div>\n\n\n\n<p>It&#8217;s that simple! You could also use a for-of loop:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>for (let cake of cakes) {\n\tconsole.log(cake);\n}<\/pre><\/div>\n\n\n\n<p>This code returns the same output as our <code>forEach<\/code> loop:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>Lemon Cake\nCarrot Cake\nBoston Cream Pie<\/pre><\/div>\n\n\n\n<p>You could opt to use a for loop to iterate through a Set but because Sets are iterable objects, it&#8217;s easier to just use a for-each or for-of loop.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Removing Duplicate Values Using Set<\/h2>\n\n\n\n<p>When you initialize a Set with an array, all duplicate values will be automatically removed. This is an incredibly useful feature.<br><\/p>\n\n\n\n<p>Let&#8217;s say that we have a list which contains a number of cake orders:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>var cakes = [\"Lemon Cake\", \"Carrot Cake\", \"Strawberry Cheesecake\", \"Lemon Cake\", \"Chocolate Cake\", \"Chocolate Fudge Cake\", \"Chocolate Cake\", \"Red Velvet Cake\"];<\/pre><\/div>\n\n\n\n<p>This Set contains all the cake orders made to the bakery. In total, there are eight values; two values are duplicates.<br><\/p>\n\n\n\n<p>Suppose that the baker wants to know what different types of cakes have been ordered, so she can start to prepare her kitchen. We could find this out by converting our Set into a list:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>var unique_cakes = new Set(cakes);\nconsole.log(unique_cakes);<\/pre><\/div>\n\n\n\n<p>Our code returns:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>Set(6) [ \"Lemon Cake\", \"Carrot Cake\", \"Strawberry Cheesecake\", \"Chocolate Cake\", \"Chocolate Fudge Cake\", \"Red Velvet Cake\" ]<\/pre><\/div>\n\n\n\n<p>Our list has been pared down to six values. These are all of the unique values from our list of orders. There&#8217;s one step left.<br><\/p>\n\n\n\n<p>We&#8217;ve got to convert our Set of cakes back to a list so that we can interact with it using standard list methods. We can do so using the <code>Array.from()<\/code> method:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>let final_cakes = Array.from(unique_cakes);\nconsole.log(final_cakes);<\/pre><\/div>\n\n\n\n<p>Our code returns:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>[ \"Lemon Cake\", \"Carrot Cake\", \"Strawberry Cheesecake\", \"Chocolate Cake\", \"Chocolate Fudge Cake\", \"Red Velvet Cake\" ]<\/pre><\/div>\n\n\n\n<p>While the output of this code is similar to our Set, there is one big difference: our data is now stored as an array. This means that we can interact with it using all the built-in JavaScript array methods.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Conclusion<\/h2>\n\n\n\n<p>The Set object allows you to store a list of items that can only contain unique values. Sets can be initialized from an existing iterable object, such as a list or a string.<br><\/p>\n\n\n\n<p>Because the Set object removes duplicate values, you can use it as a way to remove any duplicates from an array. Then, once you&#8217;re done, you can convert your Set back to an array.<br><\/p>\n\n\n\n<p>Now you&#8217;re ready to start using Sets in JavaScript like a pro!<\/p>\n","protected":false},"excerpt":{"rendered":"How to Use Sets in JavaScript Do you have a list of data that should only contain unique values? This is where the JavaScript Set data type really shines. It's a new type of object that allows you to create a collection of unique values; no duplicates are allowed within a set. In this guide,&hellip;","protected":false},"author":240,"featured_media":18771,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[11933],"tags":[],"class_list":{"0":"post-19302","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"has-post-thumbnail","7":"category-javascript"},"acf":{"post_sub_title":"","sprint_id":"","query_class":"JavaScript","school_sft":"","parent_sft":"","school_privacy_policy":"","has_review":"","is_sponser_post":"","is_guest_post":""},"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v27.4 (Yoast SEO v27.4) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>JavaScript Set: A Guide for Beginners | Career Karma<\/title>\n<meta name=\"description\" content=\"The Set data type allows you to store a set of values that cannot contain duplicates. On Career Karma, learn how to use JavaScript Sets.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/careerkarma.com\/blog\/javascript-set\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"JavaScript Set: A Guide for Beginners\" \/>\n<meta property=\"og:description\" content=\"The Set data type allows you to store a set of values that cannot contain duplicates. On Career Karma, learn how to use JavaScript Sets.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/careerkarma.com\/blog\/javascript-set\/\" \/>\n<meta property=\"og:site_name\" content=\"Career Karma\" \/>\n<meta property=\"article:publisher\" content=\"http:\/\/facebook.com\/careerkarmaapp\" \/>\n<meta property=\"article:published_time\" content=\"2020-07-10T23:17:43+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-12-01T11:54:15+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/07\/markus-spiske-MI9-PY5cyNs-unsplash.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1020\" \/>\n\t<meta property=\"og:image:height\" content=\"680\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"James Gallagher\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@career_karma\" \/>\n<meta name=\"twitter:site\" content=\"@career_karma\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"James Gallagher\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"5 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/javascript-set\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/javascript-set\\\/\"},\"author\":{\"name\":\"James Gallagher\",\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/#\\\/schema\\\/person\\\/e79364792443fbff794a144c67ec8e94\"},\"headline\":\"JavaScript Set: A Guide for Beginners\",\"datePublished\":\"2020-07-10T23:17:43+00:00\",\"dateModified\":\"2023-12-01T11:54:15+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/javascript-set\\\/\"},\"wordCount\":1068,\"commentCount\":0,\"image\":{\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/javascript-set\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/07\\\/markus-spiske-MI9-PY5cyNs-unsplash.jpg\",\"articleSection\":[\"JavaScript\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/careerkarma.com\\\/blog\\\/javascript-set\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/javascript-set\\\/\",\"url\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/javascript-set\\\/\",\"name\":\"JavaScript Set: A Guide for Beginners | Career Karma\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/javascript-set\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/javascript-set\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/07\\\/markus-spiske-MI9-PY5cyNs-unsplash.jpg\",\"datePublished\":\"2020-07-10T23:17:43+00:00\",\"dateModified\":\"2023-12-01T11:54:15+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/#\\\/schema\\\/person\\\/e79364792443fbff794a144c67ec8e94\"},\"description\":\"The Set data type allows you to store a set of values that cannot contain duplicates. On Career Karma, learn how to use JavaScript Sets.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/javascript-set\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/careerkarma.com\\\/blog\\\/javascript-set\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/javascript-set\\\/#primaryimage\",\"url\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/07\\\/markus-spiske-MI9-PY5cyNs-unsplash.jpg\",\"contentUrl\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/07\\\/markus-spiske-MI9-PY5cyNs-unsplash.jpg\",\"width\":1020,\"height\":680,\"caption\":\"Using header and divs while composing markup in HTML\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/javascript-set\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Blog\",\"item\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"JavaScript\",\"item\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/javascript\\\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"JavaScript Set: A Guide for Beginners\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/\",\"name\":\"Career Karma\",\"description\":\"Latest Coding Bootcamp News &amp; Career Hacks from Industry Insiders\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/#\\\/schema\\\/person\\\/e79364792443fbff794a144c67ec8e94\",\"name\":\"James Gallagher\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/01\\\/james-gallagher-150x150.jpg\",\"url\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/01\\\/james-gallagher-150x150.jpg\",\"contentUrl\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/01\\\/james-gallagher-150x150.jpg\",\"caption\":\"James Gallagher\"},\"description\":\"James Gallagher is a self-taught programmer and the technical content manager at Career Karma. He has experience in range of programming languages and extensive expertise in Python, HTML, CSS, and JavaScript. James has written hundreds of programming tutorials, and he frequently contributes to publications like Codecademy, Treehouse, Repl.it, Afrotech, and others.\",\"url\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/author\\\/jamesgallagher\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"JavaScript Set: A Guide for Beginners | Career Karma","description":"The Set data type allows you to store a set of values that cannot contain duplicates. On Career Karma, learn how to use JavaScript Sets.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/careerkarma.com\/blog\/javascript-set\/","og_locale":"en_US","og_type":"article","og_title":"JavaScript Set: A Guide for Beginners","og_description":"The Set data type allows you to store a set of values that cannot contain duplicates. On Career Karma, learn how to use JavaScript Sets.","og_url":"https:\/\/careerkarma.com\/blog\/javascript-set\/","og_site_name":"Career Karma","article_publisher":"http:\/\/facebook.com\/careerkarmaapp","article_published_time":"2020-07-10T23:17:43+00:00","article_modified_time":"2023-12-01T11:54:15+00:00","og_image":[{"width":1020,"height":680,"url":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/07\/markus-spiske-MI9-PY5cyNs-unsplash.jpg","type":"image\/jpeg"}],"author":"James Gallagher","twitter_card":"summary_large_image","twitter_creator":"@career_karma","twitter_site":"@career_karma","twitter_misc":{"Written by":"James Gallagher","Est. reading time":"5 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/careerkarma.com\/blog\/javascript-set\/#article","isPartOf":{"@id":"https:\/\/careerkarma.com\/blog\/javascript-set\/"},"author":{"name":"James Gallagher","@id":"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/e79364792443fbff794a144c67ec8e94"},"headline":"JavaScript Set: A Guide for Beginners","datePublished":"2020-07-10T23:17:43+00:00","dateModified":"2023-12-01T11:54:15+00:00","mainEntityOfPage":{"@id":"https:\/\/careerkarma.com\/blog\/javascript-set\/"},"wordCount":1068,"commentCount":0,"image":{"@id":"https:\/\/careerkarma.com\/blog\/javascript-set\/#primaryimage"},"thumbnailUrl":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/07\/markus-spiske-MI9-PY5cyNs-unsplash.jpg","articleSection":["JavaScript"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/careerkarma.com\/blog\/javascript-set\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/careerkarma.com\/blog\/javascript-set\/","url":"https:\/\/careerkarma.com\/blog\/javascript-set\/","name":"JavaScript Set: A Guide for Beginners | Career Karma","isPartOf":{"@id":"https:\/\/careerkarma.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/careerkarma.com\/blog\/javascript-set\/#primaryimage"},"image":{"@id":"https:\/\/careerkarma.com\/blog\/javascript-set\/#primaryimage"},"thumbnailUrl":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/07\/markus-spiske-MI9-PY5cyNs-unsplash.jpg","datePublished":"2020-07-10T23:17:43+00:00","dateModified":"2023-12-01T11:54:15+00:00","author":{"@id":"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/e79364792443fbff794a144c67ec8e94"},"description":"The Set data type allows you to store a set of values that cannot contain duplicates. On Career Karma, learn how to use JavaScript Sets.","breadcrumb":{"@id":"https:\/\/careerkarma.com\/blog\/javascript-set\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/careerkarma.com\/blog\/javascript-set\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/careerkarma.com\/blog\/javascript-set\/#primaryimage","url":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/07\/markus-spiske-MI9-PY5cyNs-unsplash.jpg","contentUrl":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/07\/markus-spiske-MI9-PY5cyNs-unsplash.jpg","width":1020,"height":680,"caption":"Using header and divs while composing markup in HTML"},{"@type":"BreadcrumbList","@id":"https:\/\/careerkarma.com\/blog\/javascript-set\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Blog","item":"https:\/\/careerkarma.com\/blog\/"},{"@type":"ListItem","position":2,"name":"JavaScript","item":"https:\/\/careerkarma.com\/blog\/javascript\/"},{"@type":"ListItem","position":3,"name":"JavaScript Set: A Guide for Beginners"}]},{"@type":"WebSite","@id":"https:\/\/careerkarma.com\/blog\/#website","url":"https:\/\/careerkarma.com\/blog\/","name":"Career Karma","description":"Latest Coding Bootcamp News &amp; Career Hacks from Industry Insiders","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/careerkarma.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/e79364792443fbff794a144c67ec8e94","name":"James Gallagher","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/01\/james-gallagher-150x150.jpg","url":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/01\/james-gallagher-150x150.jpg","contentUrl":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/01\/james-gallagher-150x150.jpg","caption":"James Gallagher"},"description":"James Gallagher is a self-taught programmer and the technical content manager at Career Karma. He has experience in range of programming languages and extensive expertise in Python, HTML, CSS, and JavaScript. James has written hundreds of programming tutorials, and he frequently contributes to publications like Codecademy, Treehouse, Repl.it, Afrotech, and others.","url":"https:\/\/careerkarma.com\/blog\/author\/jamesgallagher\/"}]}},"_links":{"self":[{"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/posts\/19302","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/users\/240"}],"replies":[{"embeddable":true,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/comments?post=19302"}],"version-history":[{"count":0,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/posts\/19302\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/media\/18771"}],"wp:attachment":[{"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/media?parent=19302"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/categories?post=19302"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/tags?post=19302"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}