JavaScript Program to get Query String Values Last Updated : 06 Nov, 2023 Summarize Comments Improve Suggest changes Share Like Article Like Report Getting query string values in JavaScript refers to extracting parameters from a URL after the "?" symbol. It allows developers to capture user input or state information passed through URLs for dynamic web content and processing within a web application. Table of Content Using URLSearchParamsUsing Pure JavaScript Approach 1: Using URLSearchParamsIn this approach, parse a URL using a URL class, and extract query parameters with searchParams.get(paramName).Print parameter value if found; otherwise, indicate it's not present in the query string.Syntax: URLSearchParams.get(name)Example: This example shows the use of the above-explained approach. JavaScript const url = require('url'); // Example URL const str1 = 'http://example.com/path?paramName=GeeksforGeeks'; // Parse the URL const parsedUrl = new URL(str1); // Get the value of a specific parameter from the query string const paramName = 'paramName'; const result = parsedUrl.searchParams.get(paramName); if (result !== null) { console.log('Value of ' + paramName + ' is: ' + result); } else { console.log(paramName + ' not found in the query string.'); } OutputValue of paramName is: GeeksforGeeks Approach 2 : Using Pure JavaScript In this approach, Create a function queryString(url) that extracts and decodes query parameters using pure JavaScript. Split the URL, parse query string, and store key-value pairs.Return the parameters object.Example: This example shows the use of the above-explained approach. JavaScript function queryString(url) { const str1 = url.split('?')[1]; const params = {}; if (str1) { const pairs = str1.split('&'); for (const pair of pairs) { const [key, value] = pair.split('='); params[key] = decodeURIComponent(value .replace(/\+/g, ' ')); } } return params; } const urlStr = 'http://example.com/path?param1=GeeksforGeeks¶m2=Noida'; const result = queryString(urlStr); console.log(result); Output{ param1: 'GeeksforGeeks', param2: 'Noida' } Comment More infoAdvertise with us Next Article JavaScript Program to get Query String Values P parzival_op Follow Improve Article Tags : JavaScript Web Technologies Geeks Premier League JavaScript-Program Geeks Premier League 2023 +1 More Similar Reads JavaScript method to get the URL without query string The task is to get the URL name of the page without using a query string with the help of JavaScript. replace() method: This method searches a string for a defined value, or a regular expression, and returns a new string with the replaced defined value. Syntax: string.replace(searchVal, newvalue) Pa 3 min read How to get URL Parameters using JavaScript ? To get URL parameters using JavaScript means extracting the query string values from a URL. URL parameters, found after the ? in a URL, pass data like search terms or user information. JavaScript can parse these parameters, allowing you to programmatically access or manipulate their values.For getti 3 min read PHP Program to Convert Array to Query String This article will show you how to convert an array to a query string in PHP. The Query String is the part of the URL that starts after the question mark(?).Example:Input: $arr = ( 'company' => 'GeeksforGeeks', 'Address' => 'Noida', 'Phone' => '9876543210');Output: company=GeeksforGeeks& 3 min read How to Get Parameter Value from Query String in ReactJS? In React query parameter are a way to pass the data as props from the url to react components. Getting parameter value from query string helps to render the dynamic data depending on the query.ApproachTo get the parameter value from query string in React we will be using the query-string packge. We 2 min read JavaScript Know the value of GET parameters from URL In this article, we will see how to get the GET parameters from a URL using JavaScript. In order to know the parameters that are passed by the "GET" method, sometimes we need to pass the Email and other details. For that purpose, we are using the following snippet of code. Example 1: This example ge 1 min read Like