How to get Values from URL Parameters using JavaScript

How to get Values from URL Parameters using JavaScript

February 07, 2023


Learn How to get values from URL Parameters using JavaScript

today I'm going to teach you how to get values from URL parameters using Javascript. there is no direct code or function to get values from URL parameters that's why we need to create functionality for it.

there are lots of way to get values fron URL in javascript. many developers has own methods to get values from URL, similarly this is my functionality.

Javascript Code:

var getUrl = window.location.search.slice(1);
      
    getUrl = getUrl.replaceAll('=', '":"');
    getUrl = getUrl.replaceAll('&', '","');
    getUrl = getUrl.replaceAll('%20', ' ');
    getUrl = '{"' + getUrl + '"}';

    var obj = JSON.parse(getUrl);
Try this code