Open In App

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 get the value of “a” parameter from the URL. 






function GET_Paramters() {
    const url =
     
    let urlObject = new URL(url);
    let get_params = urlObject.searchParams.get("a");
    console.log(get_params);
}
 
GET_Paramters();

Output
GeeksforGeeks

Example 2:This example returns the value of all the parameters from the URL. 






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

Article Tags :