I need to change the value of query parameters of the given URL irrespective of value type.
I have a function like,
function urlGenerator (key, value) {
var url = "www.domain.com/?id=10&name=xxx&dob=2018-12-13";
// change the value for given key
return url;
}
The order of query parameters are not fixed. It may be of any order. I think the solution can be found by Regex.
I need generic solution irrespective of the type of value given to above specified URL. I need to call the above method like following and must get the resultant URL.
result = urlGenerator('id', 15);
result = urlGenerator('name', 'yyy');
result = urlGenerator('dob', '2018-10-20');
Thanks in advance!!