splitting the URL using jQuery

Can i get the help of you guys as i want i can do it with url

I need to split the URL. and use last element as job_id, And then pass jkdbsbd45JubJKAAASSYT as job_Id.

URL: https://dev/job/?job_id=jkdbsbd45JubJKAAASSYT

Need to create this URL as below.

Need: https://dev/job/jkdbsbd45JubJKAAASSYT

Thanx in advance

Topic jquery-ui ajax jquery Wordpress javascript

Category Web


Not really a WordPress related question but you could do this

// creates a object from the array, one of the properies (search) contains the query
let url = new URL('https://dev/job/?job_id=jkdbsbd45JubJKAAASSYT');
// will create a object of all availalble query properites
const urlSearchParams = new URLSearchParams(url.search);
const params = Object.fromEntries(urlSearchParams.entries());
// remove ? and everything after from url
url = url.href.substring(0, url.href.indexOf('?'));

// url + params.job_id is the final url, did a console.log so you could see it in the devtools console
console.log(url + params.job_id);

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.