I have some url like this
/posts/singlepost?page=99
I need to get key and value of query in url and to put in new array, that i can loop,and use that key and value in my http request. In url page can be something else, i dont know what can be
I have some url like this
/posts/singlepost?page=99
I need to get key and value of query in url and to put in new array, that i can loop,and use that key and value in my http request. In url page can be something else, i dont know what can be
You can do something like that:
// Get params.
const params = Array.from(new URLSearchParams(location.search))
// Add a loop.
params.forEach(([key, value]) => /* key is 'page' and value is 99 */)
You can use split()
by ?
and then split()
the second element by =
let str = '/posts/singlepost?page=99';
let res = str.split('?')[1].split('=');
console.log(res)