JavaScript Program to get Query String Values Last Updated : 06 Nov, 2023 Comments Improve Suggest changes 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 How to retrieve GET parameters from JavaScript ? In order to know the parameters, those are passed by the âGETâ method, like sometimes we pass the Email-id, Password, and other details. For that purpose, We are using the following snippet of code. When you visit any website, ever thought about what the question mark '?' is doing in the address bar 2 min read How to Create Query Parameters in JavaScript ? Creating query parameters in JavaScript involves appending key-value pairs to a URL after the `?` character. This process is essential for passing data to web servers via URLs, enabling dynamic and interactive web applications through GET requests and URL manipulation. Example: Input: {'website':'ge 3 min read JavaScript - Converting Query String to Object with Null, Undefined, and Boolean Values Here are the different methods to convert query string to object with null, undefined and boolean values.1. Using URLSearchParams APIThe URLSearchParams interface provides an easy and modern way to work with query strings. It lets you easily parse the query string and convert it into a JavaScript ob 4 min read How to parse URL using JavaScript ? Given an URL and the task is to parse that URL and retrieve all the related data using JavaScript. Example: URL: https://www.geeksforgeeks.org/courses When we parse the above URL then we can find hostname: geeksforgeeks.com path: /courses Method 1: In this method, we will use createElement() method 2 min read Java Program to Get Connected to a Web Server In today's interconnected world, connecting to web servers is a fundamental skill for software developers. Whether you're building a web application that needs to fetch data from external sources, testing a web service, or even performing web scraping for research, knowing how to interact with web s 4 min read Like