Method One: Using the Charat method under String Object
The CharAt () method returns the character at the specified position.
The code is as follows |
Copy Code |
Str.charat (str.length–1) |
Note that JavaScript does not have a character data type that is different from a string type, so the character returned is a string of length 1
Method Two: Using the Substr method under the String object
The substr () method extracts a specified number of characters from the start subscript in a string.
The code is as follows |
Copy Code |
Str.substr (str.length-1,1) |
Important: ECMAscript does not standardize the method and is therefore opposed to its use.
Important: In IE 4, the value of the parameter start is invalid. In this BUG, start sets the position of the No. 0 character. In later versions, this BUG has been fixed.
Method Three: Using the Split method under String object
The split () method is used to split a string into an array of strings.
The code is as follows |
Copy Code |
var str = "123456″; Spstr = Str.split (""); SPSTR[SPSTR.LENGTH-1]; |
Method Four: Just fix it
code is as follows |
copy code |
<script Type= "Text/javascript" //<![ cdata[ var s = "Nasofj;n234n41;v"; alert ("String:" +s+ "nn" + "LaStone:" + S.replace (/^ (. *[n]) *.* (. | N) $/g, "$"); //] </script> |