light weigh
string.substring(start,end)
where
start = Required
. The position where to start the extraction. First character is at index 0`.
end = Optional
. The position (up to, but not including) where to end the extraction. If omitted, it extracts the rest of the string.
var string = "var1/var2/var3";
start = string.lastIndexOf('/'); //console.log(start); o/p:- 9
end = string.length; //console.log(end); o/p:- 14
var string_before_last_slash = string.substring(0, start);
console.log(string_before_last_slash);//o/p:- var1/var2
var string_after_last_slash = string.substring(start+1, end);
console.log(string_after_last_slash);//o/p:- var3
OR
var string_after_last_slash = string.substring(start+1);
console.log(string_after_last_slash);//o/p:- var3