I would like to take only the part using javascript
cdf28fbc167d0fa6bdbf2928f1a18235a5d2ab24659455f0108dc3bcdcbe5608
from the url:
http://localhost:3000/resetPassword/cdf28fbc167d0fa6bdbf2928f1a18235a5d2ab24650855cbe01c6b01
How can I do it?
I tried to use location but without success
CodePudding user response:
It can be achived by using lastIndexOf
and substring
:
const url = 'http://localhost:3000/resetPassword/cdf28fbc167d0fa6bdbf2928f1a18235a5d2ab24650855cbe01c6b01'
console.log(url.substring(url.lastIndexOf('/') 1))
CodePudding user response:
const url = "http://localhost:3000/resetPassword/cdf28fbc167d0fa6bdbf2928f1a18235a5d2ab24650855cbe01c6b01";
console.log(url.split("/")[4])
CodePudding user response:
You can use:
window.location.href.split("/").slice(-1)[0]