2

In PHP I am doing the below which works.

$urlParam = $_GET['abc_filter']['1e7678d987'];

But I need to do this in javascript as well.

This works for normal parameters:

    function getQueryVariable(variable)
{
       var query = window.location.search.substring(1);
       var vars = query.split("&");
       for (var i=0;i<vars.length;i++) {
               var pair = vars[i].split("=");
               if(pair[0] == variable){return pair[1];}
       }
       return(false);
}

var someVal = getQueryVariable("someVal");

But I am not sure what I would put in place 'someVal' inside getQueryVariable("someVal");

1

1 Answer 1

3

you can use URL method for parse url

const url = new URL('https://stackoverflow.com/?a=test');
console.log(url.searchParams.get('a'));
//or if you iterate params
url.searchParams.forEach((v,k)=>{
  console.log(`${k}=>${v}`);
});

Sign up to request clarification or add additional context in comments.

1 Comment

This is your application requirements, but when you are not certain about query string then you can use forEach to extract all data

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.