[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"academy-blogs-en-1-1-all-maps-in-go-and-javascript-all--*":3,"academy-blog-translations-cemyh8xgu1k5zut":75},{"data":4,"page":74,"perPage":74,"totalItems":74,"totalPages":74},[5],{"alt":6,"collectionId":7,"collectionName":8,"content":9,"cover_image":10,"cover_image_path":11,"created":12,"created_by":13,"expand":14,"id":69,"keywords":70,"locale":44,"published_at":71,"scheduled_at":13,"school_blog":66,"short_description":72,"status":64,"title":6,"updated":73,"updated_by":13,"slug":67,"views":68},"JS2GO EP.15 Using Maps in Go and JavaScript","sclblg987654321","school_blog_translations","\u003Cp>Maps, or key-value structures, are essential tools for efficiently storing and accessing data. Both Go and JavaScript support Maps, but each language has its own way of handling them. This article will guide you through creating, modifying, and accessing data in Maps, complete with code examples, pros and cons, and practical usage recommendations for real-world projects.\u003C\u002Fp>\u003Cp>&nbsp;\u003C\u002Fp>\u003Ch2>Maps in Go\u003C\u002Fh2>\u003Cp>&nbsp;\u003C\u002Fp>\u003Cp>In Go, Maps are a built-in type used to store key-value pairs.\u003C\u002Fp>\u003Cp>&nbsp;\u003C\u002Fp>\u003Cp>Declaring and Creating a Map\u003C\u002Fp>\u003Cpre>\u003Ccode class=\"language-plaintext language-go\">package main\n\nimport \"fmt\"\n\nfunc main() {\n    \u002F\u002F Create an empty map\n    m := make(map[string]int)\n\n    \u002F\u002F Add data\n    m[\"Alice\"] = 25\n    m[\"Bob\"] = 30\n\n    \u002F\u002F Read data\n    fmt.Println(\"Alice:\", m[\"Alice\"])  \u002F\u002F Alice: 25\n\n    \u002F\u002F Delete a key\n    delete(m, \"Bob\")\n\n    \u002F\u002F Check if a key exists\n    age, exists := m[\"Bob\"]\n    if !exists {\n        fmt.Println(\"Bob not found\")  \u002F\u002F Bob not found\n    }\n\n    fmt.Println(m)  \u002F\u002F map[Alice:25]\n}\n\u003C\u002Fcode>\u003C\u002Fpre>\u003Cp>&nbsp;\u003C\u002Fp>\u003Cp>Pros\u003C\u002Fp>\u003Cp>✨ Very fast data access and modification\u003Cbr>✨ Key and value types are clearly defined, reducing errors\u003C\u002Fp>\u003Cp>&nbsp;\u003C\u002Fp>\u003Cp>Cons\u003C\u002Fp>\u003Cp>⚠️ Key and value types must be explicitly defined\u003Cbr>⚠️ Cannot iterate in the order items were added (no order guarantee)\u003C\u002Fp>\u003Cp>&nbsp;\u003C\u002Fp>\u003Ch2>Maps in JavaScript\u003C\u002Fh2>\u003Cp>&nbsp;\u003C\u002Fp>\u003Cp>In JavaScript, you can use either Objects or Map (ES6).\u003C\u002Fp>\u003Cp>&nbsp;\u003C\u002Fp>\u003Cp>Using an Object as a Map\u003C\u002Fp>\u003Cpre>\u003Ccode class=\"language-javascript\">let obj = {};\nobj[\"Alice\"] = 25;\nobj[\"Bob\"] = 30;\n\nconsole.log(obj[\"Alice\"]); \u002F\u002F 25\n\ndelete obj[\"Bob\"];\nconsole.log(obj); \u002F\u002F { Alice: 25 }\n\u003C\u002Fcode>\u003C\u002Fpre>\u003Cp>&nbsp;\u003C\u002Fp>\u003Cp>Using ES6 Map Object\u003C\u002Fp>\u003Cpre>\u003Ccode class=\"language-javascript\">let map = new Map();\n\n\u002F\u002F Add data\nmap.set(\"Alice\", 25);\nmap.set(\"Bob\", 30);\n\n\u002F\u002F Read data\nconsole.log(map.get(\"Alice\")); \u002F\u002F 25\n\n\u002F\u002F Delete a key\nmap.delete(\"Bob\");\n\n\u002F\u002F Check if a key exists\nconsole.log(map.has(\"Bob\")); \u002F\u002F false\n\n\u002F\u002F Iterate through the Map\nfor (let [key, value] of map) {\n    console.log(key, value); \u002F\u002F Alice 25\n}\n\u003C\u002Fcode>\u003C\u002Fpre>\u003Cp>&nbsp;\u003C\u002Fp>\u003Cp>Pros\u003C\u002Fp>\u003Cp>✨ Supports keys of any type, not just strings\u003Cbr>✨ Can iterate in the order items were added (for ES6 Map)\u003Cbr>✨ Map methods like \u003Ccode inline=\"\">set\u003C\u002Fcode>, \u003Ccode inline=\"\">get\u003C\u002Fcode>, \u003Ccode inline=\"\">delete\u003C\u002Fcode>, and \u003Ccode inline=\"\">has\u003C\u002Fcode> are easy to use\u003C\u002Fp>\u003Cp>&nbsp;\u003C\u002Fp>\u003Cp>Cons\u003C\u002Fp>\u003Cp>⚠️ Performance may be lower than Go when handling large datasets\u003Cbr>⚠️ Must be careful to distinguish between Object and Map\u003C\u002Fp>\u003Cp>&nbsp;\u003C\u002Fp>\u003Ch2>Comparing Maps in Go and JavaScript\u003C\u002Fh2>\u003Cp>&nbsp;\u003C\u002Fp>\u003Cfigure class=\"table\">\u003Ctable>\u003Cthead>\u003Ctr>\u003Cth>Feature\u003C\u002Fth>\u003Cth>Go\u003C\u002Fth>\u003Cth>JavaScript\u003C\u002Fth>\u003C\u002Ftr>\u003C\u002Fthead>\u003Ctbody>\u003Ctr>\u003Ctd>Key Type\u003C\u002Ftd>\u003Ctd>Must specify type\u003C\u002Ftd>\u003Ctd>Any type (Map) \u002F string (Object)\u003C\u002Ftd>\u003C\u002Ftr>\u003Ctr>\u003Ctd>Value Type\u003C\u002Ftd>\u003Ctd>Must specify type\u003C\u002Ftd>\u003Ctd>Any type\u003C\u002Ftd>\u003C\u002Ftr>\u003Ctr>\u003Ctd>Iteration Order\u003C\u002Ftd>\u003Ctd>Not guaranteed\u003C\u002Ftd>\u003Ctd>ES6 Map: insertion order\u003C\u002Ftd>\u003C\u002Ftr>\u003Ctr>\u003Ctd>Performance\u003C\u002Ftd>\u003Ctd>High\u003C\u002Ftd>\u003Ctd>Medium\u003C\u002Ftd>\u003C\u002Ftr>\u003Ctr>\u003Ctd>Methods\u002FFunctions\u003C\u002Ftd>\u003Ctd>built-in: \u003Ccode inline=\"\">make\u003C\u002Fcode>, \u003Ccode inline=\"\">delete\u003C\u002Fcode>\u003C\u002Ftd>\u003Ctd>\u003Ccode inline=\"\">Map\u003C\u002Fcode>: \u003Ccode inline=\"\">set\u003C\u002Fcode>, \u003Ccode inline=\"\">get\u003C\u002Fcode>, \u003Ccode inline=\"\">has\u003C\u002Fcode>, \u003Ccode inline=\"\">delete\u003C\u002Fcode>\u003C\u002Ftd>\u003C\u002Ftr>\u003Ctr>\u003Ctd>Use Case\u003C\u002Ftd>\u003Ctd>Large data structures\u003C\u002Ftd>\u003Ctd>Flexible key-value storage\u003C\u002Ftd>\u003C\u002Ftr>\u003C\u002Ftbody>\u003C\u002Ftable>\u003C\u002Ffigure>\u003Cp>&nbsp;\u003C\u002Fp>\u003Chr>\u003Cp>&nbsp;\u003C\u002Fp>\u003Ch2>Summary and Recommendations\u003C\u002Fh2>\u003Cp>&nbsp;\u003C\u002Fp>\u003Cul>\u003Cli>Go: Maps are ideal for projects that require high performance and type safety.\u003C\u002Fli>\u003Cli>JavaScript: Maps are ideal for projects that need flexibility and keys of multiple types.\u003C\u002Fli>\u003Cli>When choosing a Map structure, consider data size, key type, and whether iteration order matters.\u003C\u002Fli>\u003C\u002Ful>\u003Cp>&nbsp;\u003C\u002Fp>\u003Ch2>Next Episode\u003C\u002Fh2>\u003Cp>&nbsp;\u003C\u002Fp>\u003Cp>In EP.16 of the JS2GO series, we will explore Methods and Interfaces in Go vs. JavaScript to understand how to create and use functions within structs and objects effectively.\u003C\u002Fp>\u003Cp>&nbsp;\u003C\u002Fp>\u003Cp data-start=\"498\" data-end=\"834\">\u003Cstrong>Read more\u003C\u002Fstrong>\u003C\u002Fp>\u003Cul>\u003Cli>\u003Cp data-start=\"498\" data-end=\"834\">\u003Ca target=\"_blank\" rel=\"noopener noreferrer\" href=\"https:\u002F\u002Fwww.superdev.school\u002Fblogs\u002Fcategories\u002FGolang\">\u003Cstrong>Golang The Series\u003C\u002Fstrong>\u003C\u002Fa>\u003C\u002Fp>\u003C\u002Fli>\u003Cli>\u003Cp data-start=\"498\" data-end=\"834\">\u003Ca target=\"_blank\" rel=\"noopener noreferrer\" href=\"https:\u002F\u002Fwww.superdev.school\u002Fblogs\u002Fcategories\u002FJS2GO\">\u003Cstrong>JS2GO\u003C\u002Fstrong>\u003C\u002Fa>\u003C\u002Fp>\u003C\u002Fli>\u003Cli>\u003Cp data-start=\"498\" data-end=\"834\">\u003Ca target=\"_blank\" rel=\"noopener noreferrer\" href=\"https:\u002F\u002Fwww.superdev.school\u002Fen\u002Fblogs\u002Fcategories\u002FTailwind%20CSS\">\u003Cstrong>10 Eps That Will Make You a Pro Tailwind CSS Overnight\u003C\u002Fstrong>\u003C\u002Fa>\u003C\u002Fp>\u003C\u002Fli>\u003C\u002Ful>\u003Cp>\u003Cstrong>🔵 Facebook: \u003C\u002Fstrong>\u003Ca target=\"_blank\" rel=\"noopener noreferrer\" href=\"https:\u002F\u002Fwww.facebook.com\u002Fsuperdev.school.th\">\u003Cstrong>Superdev School &nbsp;(Superdev)\u003C\u002Fstrong>\u003C\u002Fa>\u003C\u002Fp>\u003Cp>\u003Cstrong>📸 Instagram: \u003C\u002Fstrong>\u003Ca target=\"_blank\" rel=\"noopener noreferrer\" href=\"https:\u002F\u002Fwww.instagram.com\u002Fsuperdevschool\u002F\">\u003Cstrong>superdevschool\u003C\u002Fstrong>\u003C\u002Fa>\u003C\u002Fp>\u003Cp>\u003Cstrong>🎬 TikTok: \u003C\u002Fstrong>\u003Ca target=\"_blank\" rel=\"noopener noreferrer\" href=\"https:\u002F\u002Fwww.tiktok.com\u002F@superdevschool\">\u003Cstrong>superdevschool\u003C\u002Fstrong>\u003C\u002Fa>\u003C\u002Fp>\u003Cp class=\"\" data-start=\"5978\" data-end=\"6095\">\u003Cstrong>🌐 Website: \u003C\u002Fstrong>\u003Ca target=\"_blank\" rel=\"noopener noreferrer\" href=\"https:\u002F\u002Fwww.superdev.school\u002F\">\u003Cstrong>www.superdev.school\u003C\u002Fstrong>\u003C\u002Fa>\u003C\u002Fp>","30_11zon_aexvjkxbqy.webp","https:\u002F\u002Ftwsme-r2.tumwebsme.com\u002Fsclblg987654321\u002Fppi5xo3o2a4y8ej\u002F30_11zon_aexvjkxbqy.webp","2026-03-04 08:46:46.843Z","",{"keywords":15,"locale":38,"school_blog":48},[16,23,28,33],{"collectionId":17,"collectionName":18,"created":19,"created_by":13,"id":20,"name":21,"updated":22,"updated_by":13},"sclkey987654321","school_keywords","2026-03-04 08:46:46.543Z","f9lax9ydi0tawfj","Maps","2026-04-10 16:13:19.178Z",{"collectionId":17,"collectionName":18,"created":24,"created_by":13,"id":25,"name":26,"updated":27,"updated_by":13},"2026-03-04 08:20:42.484Z","vslzz9nvv6n77cx","JavaScript","2026-04-10 16:07:28.339Z",{"collectionId":17,"collectionName":18,"created":29,"created_by":13,"id":30,"name":31,"updated":32,"updated_by":13},"2026-03-04 08:20:11.547Z","ey3puyme01a9bsw","Go","2026-04-10 16:07:25.893Z",{"collectionId":17,"collectionName":18,"created":34,"created_by":13,"id":35,"name":36,"updated":37,"updated_by":13},"2026-03-04 08:20:33.316Z","ln1ntwattzmxo0o","programming","2026-04-10 16:07:27.299Z",{"code":39,"collectionId":40,"collectionName":41,"created":42,"flag":43,"id":44,"is_default":45,"label":46,"updated":47},"en","pbc_1989393366","locales","2026-01-22 11:00:02.726Z","twemoji:flag-united-states","qv9c1llfov2d88z",false,"English","2026-04-10 15:42:46.825Z",{"category":49,"collectionId":50,"collectionName":51,"created":13,"expand":52,"id":66,"slug":67,"updated":13,"views":68},"hsa1afr8fcnd6qb","pbc_2105096300","school_blogs",{"category":53},{"blogIds":54,"collectionId":55,"collectionName":56,"created":57,"created_by":13,"id":49,"image":58,"image_alt":13,"image_path":59,"label":60,"name":61,"priority":62,"publish_at":63,"scheduled_at":13,"status":64,"updated":65,"updated_by":13},[],"sclcatblg987654321","school_category_blogs","2026-03-04 08:24:37.986Z","js2_go_2_11zon_y6paxmuz32.webp","https:\u002F\u002Ftwsme-r2.tumwebsme.com\u002Fsclcatblg987654321\u002Fhsa1afr8fcnd6qb\u002Fjs2_go_2_11zon_y6paxmuz32.webp",{"en":61,"th":61},"JS2GO",10,"2025-08-11 03:41:08.820Z","published","2026-04-25 02:32:14.339Z","cemyh8xgu1k5zut","maps-in-go-and-javascript",211,"ppi5xo3o2a4y8ej",[20,25,30,35],"2025-08-27 11:36:47.110Z","Learn how to create, modify, and access data in Maps in Go and JavaScript, with pros, cons, and best practices for real projects.","2026-04-25 02:48:07.967Z",1,{"th":67,"en":67}]