-3

I'm using filestack, when ever I upload an image it creates an unique url for the uploaded Image. I want to get hold of a specific part of a url to a variable.

https://www.filestackapi.com/api/file/qiXTZ0dQUGPQRG4GH0Cy

https://www.filestackapi.com/api/file/"qiXTZ0dQUGPQRG4GH0Cy"

The above Url belongs to an image, but I want get hold of the quoted part to a variable, how to do that?

KayR
  • 50
  • 9

1 Answers1

3

You can search for the last index of / in the url then make a substring of the url starting from that point.

var url = 'https://www.filestackapi.com/api/file/qiXTZ0dQUGPQRG4GH0Cy';
var lastIndex = url.lastIndexOf("/");
var searched = url.substring(lastIndex + 1);

// searched = qiXTZ0dQUGPQRG4GH0Cy
Nikhilesh K V
  • 1,480
  • 13
  • 20
Davide Lorenzo MARINO
  • 26,420
  • 4
  • 39
  • 56