0

There are hundreds of example out here showing how to get URL parameters but I couldn't find any to list ONLY parameters (variables) name and not values?

For example, if I have something like:

www.mydomain.com/filtres?makes=honda,mazda,jeep&models=crv,cx5,wamgler&years=2008

I want to get only makes,models,years and if URL change to

www.mydomain.com/filtres?makes=honda,mazda,jeep&models=crv,cx5,wamgler

should be like makes,models

or on

www.mydomain.com/filtres?makes=honda,mazda,jeep&models=crv,cx5,wamgler&years=2008,2010&city=vancouver

the out should be like makes,models,years,city

2 Answers 2

1

You can use URLSearchParams

Sample:

const queryString = "?makes=honda,mazda,jeep&models=crv,cx5,wamgler&years=2008"

const urlParams = new URLSearchParams(queryString);

console.log([...new URLSearchParams(urlParams).keys()]);

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

Comments

1

console.log(
  [...new URLSearchParams(window.location.search).keys()].join(',')
);

Comments

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.