var path = 'example.com/user/john/red'
path.substr(0, path.lastIndexOf("/"))
I got example.com/user/john
how to get only example.com/user/? means lastSecondIndexOf, but there's no such method.
var path = 'example.com/user/john/red'
path.substr(0, path.lastIndexOf("/"))
I got example.com/user/john
how to get only example.com/user/? means lastSecondIndexOf, but there's no such method.
The function .lastIndexOf
takes a second parameter for fromIndex
, and you could use the last index of the slash in the parameter:
path.substr(0, path.lastIndexOf("/",path.lastIndexOf("/")-1));