Back to articles
Map & Set: The Underrated Heroes of JavaScript

Map & Set: The Underrated Heroes of JavaScript

via Dev.to WebdevKunal

While writing the blog on Array method , I have came across some topics that are new to me and Map and Set are one of them. If you’d like to explore them too 👇 If You Don’t Know These Array Methods, We Need to Talk. Kunal ・ Mar 3 #javascript #discuss #node #computerscience So in this blog we will cover : Topics to Cover Before Map & Set (The Old Way) What Map is Difference between Map and Object What Set is Difference between Set and Array When to use Map and Set Before Map & Set Before learning Set and Map , I tried doing things in the old ways using array and objects . For Map we do const data = {}; data [ " name " ] = " Kunal " ; data [ " age " ] = 21 ; console . log ( data [ " name " ]); // Kunal For Set we do const arr = [ 1 , 2 , 2 , 3 , 3 , 5 ] const unique = [] for ( let i = 0 ; i < arr . length ; i ++ ) { if ( ! unique . includes ( arr [ i ])){ unique . push ( arr [ i ]) } } console . log ( unique ); // [1,2,3,5] It worked but it required more code and wasn't clean or efficien

Continue reading on Dev.to Webdev

Opens in a new tab

Read Full Article
2 views

Related Articles