I am trying to figure out how to get the second to last index of a character in a string.
For example, I have a string like so:
http://www.example.com/website/projects/2
I currently get the number 2
by using
$(location).attr('href').substring($(location).attr('href').lastIndexOf('/')+1);
But what if I want to get the word projects
?
Can anybody help me out with this? Thanks in advance!
str.lastIndexOf('/', str.lastIndexOf('/'))
. See the documentation: developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/… – Felix Kling Aug 15 '14 at 17:17