[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"academy-blogs-en-1-1-all-js2go-ep36-implementing-searching-algorithms-in-go-and-javascript-all--*":3,"academy-blog-translations-s7er17urgojggc6":80},{"data":4,"page":79,"perPage":79,"totalItems":79,"totalPages":79},[5],{"alt":6,"collectionId":7,"collectionName":8,"content":9,"cover_image":10,"cover_image_path":11,"created":12,"created_by":13,"expand":14,"id":74,"keywords":75,"locale":49,"published_at":76,"scheduled_at":13,"school_blog":71,"short_description":77,"status":69,"title":6,"updated":78,"updated_by":13,"slug":72,"views":73},"JS2GO EP.36 Implementing Searching Algorithms in Go and JavaScript","sclblg987654321","school_blog_translations","\u003Cp>Searching is one of the most fundamental processes in every software system — whether it’s:\u003C\u002Fp>\u003Cul>\u003Cli>Searching for users in a database\u003C\u002Fli>\u003Cli>Finding products in an online store\u003C\u002Fli>\u003Cli>Or locating words within a document\u003C\u002Fli>\u003C\u002Ful>\u003Cp>&nbsp;\u003C\u002Fp>\u003Cp>A well-designed search algorithm can make your system respond faster and utilize resources more efficiently.\u003C\u002Fp>\u003Cp>&nbsp;\u003C\u002Fp>\u003Cp>In this article, we’ll compare Searching Algorithms between JavaScript and Go, focusing on three main techniques:\u003C\u002Fp>\u003Cp>1️⃣ Linear Search\u003Cbr>2️⃣ Binary Search\u003Cbr>3️⃣ Map-based Lookup\u003C\u002Fp>\u003Cp>&nbsp;\u003C\u002Fp>\u003Cp>Along with practical insights on when to use each approach in real-world systems 🚀\u003C\u002Fp>\u003Cp>&nbsp;\u003C\u002Fp>\u003Ch2>1. Linear Search — Sequential Search\u003C\u002Fh2>\u003Cp>&nbsp;\u003C\u002Fp>\u003Cp>Concept:\u003Cbr>Iterate through each element one by one until the target value is found (or the list ends).\u003C\u002Fp>\u003Cp>&nbsp;\u003C\u002Fp>\u003Ch3>🔹 JavaScript: Linear Search\u003C\u002Fh3>\u003Cpre>\u003Ccode class=\"language-javascript\">function linearSearch(arr, target) {\n  for (let i = 0; i &lt; arr.length; i++) {\n    if (arr[i] === target) return i;\n  }\n  return -1;\n}\n\nconst nums = [10, 25, 30, 45, 60];\nconsole.log(linearSearch(nums, 30));  \u002F\u002F Output: 2\nconsole.log(linearSearch(nums, 99));  \u002F\u002F Output: -1\n\u003C\u002Fcode>\u003C\u002Fpre>\u003Cp>&nbsp;\u003C\u002Fp>\u003Ch3>🔹 Go: Linear Search\u003C\u002Fh3>\u003Cpre>\u003Ccode class=\"language-plaintext language-go\">package main\n\nimport \"fmt\"\n\nfunc linearSearch(arr []int, target int) int {\n\tfor i, v := range arr {\n\t\tif v == target {\n\t\t\treturn i\n\t\t}\n\t}\n\treturn -1\n}\n\nfunc main() {\n\tnums := []int{10, 25, 30, 45, 60}\n\tfmt.Println(linearSearch(nums, 30)) \u002F\u002F Output: 2\n\tfmt.Println(linearSearch(nums, 99)) \u002F\u002F Output: -1\n}\n\u003C\u002Fcode>\u003C\u002Fpre>\u003Cp>&nbsp;\u003C\u002Fp>\u003Cp>Summary:\u003Cbr>✅ Simple and works for any dataset\u003Cbr>❌ Inefficient for large datasets\u003Cbr>Time Complexity: O(n)\u003C\u002Fp>\u003Cp>&nbsp;\u003C\u002Fp>\u003Ch2>2. Binary Search — Divide and Conquer\u003C\u002Fh2>\u003Cp>&nbsp;\u003C\u002Fp>\u003Cp>Concept:\u003Cbr>Works only on sorted data by dividing the search range in half with each iteration, drastically reducing search time.\u003C\u002Fp>\u003Cp>&nbsp;\u003C\u002Fp>\u003Ch3>🔹 JavaScript: Binary Search\u003C\u002Fh3>\u003Cpre>\u003Ccode class=\"language-javascript\">function binarySearch(arr, target) {\n  let left = 0;\n  let right = arr.length - 1;\n\n  while (left &lt;= right) {\n    const mid = Math.floor((left + right) \u002F 2);\n    if (arr[mid] === target) return mid;\n    if (arr[mid] &lt; target) left = mid + 1;\n    else right = mid - 1;\n  }\n\n  return -1;\n}\n\nconst sorted = [10, 25, 30, 45, 60];\nconsole.log(binarySearch(sorted, 45)); \u002F\u002F Output: 3\n\u003C\u002Fcode>\u003C\u002Fpre>\u003Cp>&nbsp;\u003C\u002Fp>\u003Ch3>🔹 Go: Binary Search\u003C\u002Fh3>\u003Cpre>\u003Ccode class=\"language-plaintext language-go\">package main\n\nimport \"fmt\"\n\nfunc binarySearch(arr []int, target int) int {\n\tleft, right := 0, len(arr)-1\n\tfor left &lt;= right {\n\t\tmid := (left + right) \u002F 2\n\t\tif arr[mid] == target {\n\t\t\treturn mid\n\t\t}\n\t\tif arr[mid] &lt; target {\n\t\t\tleft = mid + 1\n\t\t} else {\n\t\t\tright = mid - 1\n\t\t}\n\t}\n\treturn -1\n}\n\nfunc main() {\n\tsorted := []int{10, 25, 30, 45, 60}\n\tfmt.Println(binarySearch(sorted, 45)) \u002F\u002F Output: 3\n}\n\u003C\u002Fcode>\u003C\u002Fpre>\u003Cp>&nbsp;\u003C\u002Fp>\u003Cp>Summary:\u003Cbr>✅ Much faster for sorted data\u003Cbr>❌ Not applicable for unsorted lists\u003Cbr>Time Complexity: O(log n)\u003C\u002Fp>\u003Cp>&nbsp;\u003C\u002Fp>\u003Ch2>3. Map-based Lookup — Key-Value Search\u003C\u002Fh2>\u003Cp>&nbsp;\u003C\u002Fp>\u003Cp>Concept:\u003Cbr>Instead of searching linearly, data is stored as key-value pairs, allowing direct access to values in constant time.\u003C\u002Fp>\u003Cp>&nbsp;\u003C\u002Fp>\u003Ch3>🔹 JavaScript: Using Map\u003C\u002Fh3>\u003Cpre>\u003Ccode class=\"language-javascript\">const userMap = new Map();\nuserMap.set(\"john\", { age: 25 });\nuserMap.set(\"jane\", { age: 30 });\n\nconsole.log(userMap.get(\"john\"));  \u002F\u002F { age: 25 }\nconsole.log(userMap.has(\"alice\")); \u002F\u002F false\n\u003C\u002Fcode>\u003C\u002Fpre>\u003Cp>&nbsp;\u003C\u002Fp>\u003Ch3>🔹 Go: Using map\u003C\u002Fh3>\u003Cpre>\u003Ccode class=\"language-plaintext language-go\">package main\n\nimport \"fmt\"\n\nfunc main() {\n\tusers := map[string]int{\n\t\t\"john\": 25,\n\t\t\"jane\": 30,\n\t}\n\n\tif age, exists := users[\"john\"]; exists {\n\t\tfmt.Println(\"John:\", age)\n\t} else {\n\t\tfmt.Println(\"Not found\")\n\t}\n}\n\u003C\u002Fcode>\u003C\u002Fpre>\u003Cp>&nbsp;\u003C\u002Fp>\u003Cp>Summary:\u003Cbr>✅ Fastest search method (O(1))\u003Cbr>✅ Ideal for frequent lookups — such as caching, routing, or user data retrieval\u003Cbr>❌ Consumes slightly more memory\u003C\u002Fp>\u003Cp>&nbsp;\u003C\u002Fp>\u003Ch2>4. Searching Algorithm Comparison\u003C\u002Fh2>\u003Cp>&nbsp;\u003C\u002Fp>\u003Cfigure class=\"table\">\u003Ctable>\u003Cthead>\u003Ctr>\u003Cth>Search Method\u003C\u002Fth>\u003Cth>Time Complexity\u003C\u002Fth>\u003Cth>Requires Sorted Data\u003C\u002Fth>\u003Cth>Speed\u003C\u002Fth>\u003Cth>Best For\u003C\u002Fth>\u003C\u002Ftr>\u003C\u002Fthead>\u003Ctbody>\u003Ctr>\u003Ctd>Linear Search\u003C\u002Ftd>\u003Ctd>O(n)\u003C\u002Ftd>\u003Ctd>❌ No\u003C\u002Ftd>\u003Ctd>Slow\u003C\u002Ftd>\u003Ctd>Small \u002F Unsorted Data\u003C\u002Ftd>\u003C\u002Ftr>\u003Ctr>\u003Ctd>Binary Search\u003C\u002Ftd>\u003Ctd>O(log n)\u003C\u002Ftd>\u003Ctd>✅ Yes\u003C\u002Ftd>\u003Ctd>Fast\u003C\u002Ftd>\u003Ctd>Sorted Data\u003C\u002Ftd>\u003C\u002Ftr>\u003Ctr>\u003Ctd>Map Lookup\u003C\u002Ftd>\u003Ctd>O(1)\u003C\u002Ftd>\u003Ctd>❌ No\u003C\u002Ftd>\u003Ctd>Very Fast\u003C\u002Ftd>\u003Ctd>Frequent Lookups \u002F Key-Value Data\u003C\u002Ftd>\u003C\u002Ftr>\u003C\u002Ftbody>\u003C\u002Ftable>\u003C\u002Ffigure>\u003Cp>&nbsp;\u003C\u002Fp>\u003Ch2>5. Best Practices for Real Systems\u003C\u002Fh2>\u003Cp>&nbsp;\u003C\u002Fp>\u003Cp>🧭 Linear Search → Best for small datasets or when the data is unsorted.\u003Cbr>⚡ Binary Search → Perfect for sorted datasets like numeric ranges or product lists.\u003C\u002Fp>\u003Cp>\u003Cbr>🚀 Map-based Lookup → Best for frequent searches such as:\u003C\u002Fp>\u003Cul>\u003Cli>Session Management\u003C\u002Fli>\u003Cli>API Caching\u003C\u002Fli>\u003Cli>User or Configuration Data\u003C\u002Fli>\u003C\u002Ful>\u003Cp>&nbsp;\u003C\u002Fp>\u003Cp>Examples:\u003C\u002Fp>\u003Cul>\u003Cli>Login System → Map-based Lookup (username → user info)\u003C\u002Fli>\u003Cli>Autocomplete System → Binary Search\u003C\u002Fli>\u003Cli>Educational \u002F Demo Systems → Linear Search\u003C\u002Fli>\u003C\u002Ful>\u003Cp>&nbsp;\u003C\u002Fp>\u003Chr>\u003Cp>&nbsp;\u003C\u002Fp>\u003Ch2>Conclusion\u003C\u002Fh2>\u003Cp>&nbsp;\u003C\u002Fp>\u003Cp>Choosing the right search algorithm can greatly improve your system’s performance — especially when working with large-scale datasets.\u003C\u002Fp>\u003Cp>&nbsp;\u003C\u002Fp>\u003Cp>💻 JavaScript → Great for experimenting and implementing algorithms on the frontend.\u003Cbr>⚙️ Go → Ideal for production-level systems requiring high performance and efficient memory management.\u003C\u002Fp>\u003Cp>&nbsp;\u003C\u002Fp>\u003Ch2>Next Episode\u003C\u002Fh2>\u003Cp>&nbsp;\u003C\u002Fp>\u003Cp>In EP.37 of the JS2GO series,\u003Cbr>we’ll dive into Recursion and Iteration in JavaScript and Go,\u003Cbr>comparing how both languages handle looping vs self-calling functions — and which one performs better in terms of speed and readability 🧠\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.academy.th\">\u003Cstrong>Superdev Academy\u003C\u002Fstrong>\u003C\u002Fa>\u003C\u002Fp>\u003Cp>\u003Cstrong>🔴 YouTube: \u003C\u002Fstrong>\u003Ca target=\"_blank\" rel=\"noopener noreferrer\" href=\"https:\u002F\u002Fwww.youtube.com\u002Fchannel\u002FUC2eI2RxcA2zbTqZyHyWIfRg\">\u003Cstrong>Superdev Academy\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>Superdev Academy\u003C\u002Fstrong>\u003C\u002Fa>\u003C\u002Fp>\u003Cp>\u003Cstrong>🎬 TikTok: \u003C\u002Fstrong>\u003Ca target=\"_blank\" rel=\"noopener noreferrer\" href=\"https:\u002F\u002Fwww.tiktok.com\u002F@superdevacademy?lang=th-TH\">\u003Cstrong>https:\u002F\u002Fwww.tiktok.com\u002F@superdevacademy?lang=th-TH\u003C\u002Fstrong>\u003C\u002Fa>\u003C\u002Fp>\u003Cp>\u003Cstrong>🌐 Website: \u003C\u002Fstrong>\u003Ca target=\"_blank\" rel=\"noopener noreferrer\" href=\"https:\u002F\u002Fwww.superdevacademy.com\u002Fen\">\u003Cstrong>https:\u002F\u002Fwww.superdevacademy.com\u002Fen\u003C\u002Fstrong>\u003C\u002Fa>\u003Cstrong>&nbsp;\u003C\u002Fstrong>\u003C\u002Fp>","72_11zon_y60f66gda8.webp","https:\u002F\u002Ftwsme-r2.tumwebsme.com\u002Fsclblg987654321\u002Fduvedg12cqdatir\u002F72_11zon_y60f66gda8.webp","2026-03-04 08:45:32.876Z","",{"keywords":15,"locale":43,"school_blog":53},[16,23,28,33,38],{"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:20:42.484Z","vslzz9nvv6n77cx","JavaScript","2026-04-10 16:07:28.339Z",{"collectionId":17,"collectionName":18,"created":24,"created_by":13,"id":25,"name":26,"updated":27,"updated_by":13},"2026-03-04 08:20:11.547Z","ey3puyme01a9bsw","Go","2026-04-10 16:07:25.893Z",{"collectionId":17,"collectionName":18,"created":29,"created_by":13,"id":30,"name":31,"updated":32,"updated_by":13},"2026-03-04 08:45:32.020Z","8vrqzeheyjmdnla","Binary Search","2026-04-10 16:12:59.578Z",{"collectionId":17,"collectionName":18,"created":34,"created_by":13,"id":35,"name":36,"updated":37,"updated_by":13},"2026-03-04 08:45:32.242Z","qrrtdp2now459ki","Linear Search","2026-04-10 16:12:59.642Z",{"collectionId":17,"collectionName":18,"created":39,"created_by":13,"id":40,"name":41,"updated":42,"updated_by":13},"2026-03-04 08:34:57.930Z","3j6u3nyhnmlp6ld","Searching Algorithms","2026-04-10 16:12:34.004Z",{"code":44,"collectionId":45,"collectionName":46,"created":47,"flag":48,"id":49,"is_default":50,"label":51,"updated":52},"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":54,"collectionId":55,"collectionName":56,"created":13,"expand":57,"id":71,"slug":72,"updated":13,"views":73},"hsa1afr8fcnd6qb","pbc_2105096300","school_blogs",{"category":58},{"blogIds":59,"collectionId":60,"collectionName":61,"created":62,"created_by":13,"id":54,"image":63,"image_alt":13,"image_path":64,"label":65,"name":66,"priority":67,"publish_at":68,"scheduled_at":13,"status":69,"updated":70,"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":66,"th":66},"JS2GO",10,"2025-08-11 03:41:08.820Z","published","2026-04-25 02:32:14.339Z","s7er17urgojggc6","js2go-ep36-implementing-searching-algorithms-in-go-and-javascript",205,"duvedg12cqdatir",[20,25,30,35,40],"2025-11-12 02:36:41.559Z","Explore three fundamental search techniques — Linear Search, Binary Search, and Map-based Lookup — with real code examples in JavaScript and Go, and learn how to choose the best one for production systems.","2026-04-25 02:47:54.341Z",1,{"th":72,"en":72}]