How to Get The Last Character of a String Using jQuery?
You can use the .slice() method, its cross browser compatible.
var id = "example1"; id.slice(-1); //Outputs: 1Getting the last character is easy, as you can treat strings as an array:
var id = "example2"; var lastChar = id[id.length-1]; //Outputs: 2To get a section of a string, you can use the substr function
var id = "example3"; id.substr(id.length-1); //Outputs: 3
Comments
Post a Comment