Friday, July 28, 2017

How to find current url & last 2 character of current url using java script.

Current URL & Pathname :

var pathname = window.location.pathname;       // Returns path only
var url      = window.location.href;                     // Returns full URL
alert(pathname);
alert(url);


Current URL Last 2 Character:

var url      = window.location.href.slice(-2);     // Returns last 2 character from current URL.
alert(url);

var member = "my name is amar";
var last2 = member.slice(-2);
alert(last2);        // returns "ar"

$rest = substr("abcdef", -1);    // returns "f"