JavaScript Know the value of GET parameters from URL
Last Updated :
15 Dec, 2023
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 get the value of “a” parameter from the URL.
Javascript
function GET_Paramters() {
const url =
let urlObject = new URL(url);
let get_params = urlObject.searchParams.get( "a" );
console.log(get_params);
}
GET_Paramters();
|
Example 2:This example returns the value of all the parameters from the URL.
Javascript
function GET_Paramters() {
const url =
let urlObject = new URL(url);
let a = urlObject.searchParams.get( "a" );
let b = urlObject.searchParams.get( "b" );
let c = urlObject.searchParams.get( "c" );
console.log(a);
console.log(b);
console.log(c);
}
GET_Paramters();
|
Output
GeeksforGeeks
100
Computer Science portal for Geeks
Share your thoughts in the comments
Please Login to comment...