CopyPastor

Detecting plagiarism made easy.

Score: 0.8464005142157579; Reported for: String similarity Open both answers

Possible Plagiarism

Plagiarized on 2018-08-14
by Ramesh

Original Post

Original - Posted on 2011-01-21
by Frédéric Hamidi



            
Present in both answers; Present only in the new answer; Present only in the old answer;

You can use the [lastIndexOf()][1] function to locate the last occurrence of the `/` character in your URL, then the [substr()][2] function to return the substring starting from that location:
window.alert(this.href.substr(this.href.lastIndexOf('/') + 1));
That way, you'll avoid creating an array containing all your URL segments, as `split()` does.

[1]: http://msdn.microsoft.com/en-us/library/6d20k718.aspx [2]: http://msdn.microsoft.com/en-us/library/0esxc5wy.aspx
You can also use the [lastIndexOf()][1] function to locate the last occurrence of the `/` character in your URL, then the [substr()][2] function to return the substring starting from that location:
window.alert(this.href.substr(this.href.lastIndexOf('/') + 1));
That way, you'll avoid creating an array containing all your URL segments, as `split()` does.

[1]: http://msdn.microsoft.com/en-us/library/6d20k718.aspx [2]: http://msdn.microsoft.com/en-us/library/0esxc5wy.aspx

        
Present in both answers; Present only in the new answer; Present only in the old answer;