0

Hello friends i have website url ="https://www.example/en_uk/cgid=ladywears&middle=20&end=100" I need to extract the value of parameter "middle" and "end" which can be any numeric value from 10 to 10000. Have 1 condition which need to fulfilled -- Url will be passed dynamically and the program should only run if it has exact "middle" and "end" word matching in it .Need help in writing it in JavaScript .

Thanks in advance

0

1 Answer 1

1

You can use URLSearchParams to parse the params.

In your real environment, you must use var url = window.location.search; to get the current URL. In the below example, I just use your provided URL instead of window.location.search;.

// Use window.location.search in your live environment
// var url = window.location.search;

var url = "https://www.example/en_uk/cgid=ladywears&middle=20&end=100";
const urlParams = new URLSearchParams(url);
const middle = urlParams.get('middle');
const end = urlParams.get('end');

console.log('middle', middle);
console.log('end', end);

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

1 Comment

Thanks but is there any way by which we can split the url and extract the value of end and middle .

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.