-2

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

freedomn-m
  • 27,664
  • 8
  • 35
  • 57

3 Answers3

1

It can be achived by using lastIndexOf and substring:

const url = 'http://localhost:3000/resetPassword/cdf28fbc167d0fa6bdbf2928f1a18235a5d2ab24650855cbe01c6b01'

console.log(url.substring(url.lastIndexOf('/') + 1))
Yakupguly Malikov
  • 584
  • 1
  • 1
  • 12
0
const url = "http://localhost:3000/resetPassword/cdf28fbc167d0fa6bdbf2928f1a18235a5d2ab24650855cbe01c6b01";

console.log(url.split("/")[4])
  • Please read [answer] and [edit] your answer to contain an explanation as to why this code would actually solve the problem at hand. Always remember that you're not only solving the problem, but are also educating the OP and any future readers of this post – chrslg Jan 13 '23 at 16:35
0

You can use:

window.location.href.split("/").slice(-1)[0]