Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

get last string after / in javascript

// Regex
var result = /[^/]*$/.exec("foo/bar/test.html")[0];

// Using lastIndexOf and substring
var str = "foo/bar/test.html";
var n = str.lastIndexOf('/');
var result = str.substring(n + 1);

// Using Array#split
var parts = "foo/bar/test.html".split("/");
var result = parts[parts.length - 1]; // Or parts.pop();
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #string #javascript
ADD COMMENT
Topic
Name
2+5 =