I am already trying for over an hour and cant figure out the right way to do it, although it is probably pretty easy:
I have something like this : foo/bar/test
Jquery:
var afterDot = value.substr(value.lastIndexOf('_') + 1);
Javascript:
var myString = 'asd/f/df/xc/asd/test.jpg'
var parts = myString.split('/');
var answer = parts[parts.length - 1];
console.log(answer);
Replace '_' || '/' to your own need
Try this:
const url = "files/images/gallery/image.jpg";
console.log(url.split("/").pop());
As required in Question::
var string1= "foo/bar/test.html";
if(string1.contains("/"))
{
var string_parts = string1.split("/");
var result = string_parts[string_parts.length - 1];
console.log(result);
}
and for question asked on url (asked for one occurence of '=' )::
[http://stackoverflow.com/questions/24156535/how-to-split-a-string-after-a-particular-character-in-jquery][1]
var string1= "Hello how are =you";
if(string1.contains("="))
{
var string_parts = string1.split("=");
var result = string_parts[string_parts.length - 1];
console.log(result);
}
Try;
var str = "foo/bar/test.html"; var tmp = str.split("/"); alert(tmp.pop());