How to get All URL Parameters with Javascript

Last updated Jun 29, 2021

In this Javascript example we will cover how to read all url parameters from the URL. To do this we will use URLSearchParams URLSearchParams  is an interface which will provide methods to get the parameters.

First we will split the given url with delimeter '?' by passing the spilt() method



Get all parameters from URL using Javascript

Here is the example to get all the parameters from the url


!DOCTYPE html>

        How To Get All URL Parameters
        using JavaScript?

table {
  font-family: Arial, Helvetica, sans-serif;
  border-collapse: collapse;
  width: 100%;

 td, th {
  border: 1px solid #ddd;
  padding: 8px;

 tr:nth-child(even){background-color: #f2f2f2;}

 tr:hover {background-color: #ddd;}

 th {
  padding-top: 12px;
  padding-bottom: 12px;
  text-align: left;
  background-color: #04AA6D;
  color: white;

<h1 style="color:green;">

    How To Get All URL Parameters
    With JavaScript?

    We will fetch all parameters from this url

    Click on the button to get all the
    url parameters.
<div id="container">

<button onclick="getParameters()">
    Get URL parameters

function getParameters() {

         let urlString= ''
            let paramString = urlString.split('?')[1];

            let queryString = new URLSearchParams(paramString);

        let data='<table><tr><th>Key</th><th>Value</th></tr>';
            for (let pair of queryString.entries()) {

                console.log("Key is:" + pair[0] +"And values is: "+pair[1]);

         let ele = document.getElementById('container');
        ele.innerHTML += data;




Article Contributed By :