Home>Article>Web Front-end> How to get the last few digits of a string in javascript
In JavaScript, you can use the substring method to remove the last few digits of a string. The syntax format is "string object.substring (first character position, last character position)"; this method is used to extract characters The character in the string between the two specified subscripts.
The operating environment of this tutorial: windows7 system, javascript version 1.8.5, Dell G3 computer.
The code is as follows:
var str="abcdefghhhh";//截取后4位 str.substring(str.length-4);
The substring() method is used to extract the characters between two specified subscripts in the string.
Syntax
stringObject.substring(start,stop)
Return value
A new string value containing a substring of stringObject whose The content is all characters from start to stop-1, and its length is stop minus start.
Explanation
The substring returned by the substring() method includes the characters at start, but does not include the characters at stop.
If the parameters start and stop are equal, then this method returns an empty string (that is, a string with a length of 0). If start is greater than stop , then the method will swap the two parameters before extracting the substring.
[Recommended learning:javascript advanced tutorial]
The above is the detailed content of How to get the last few digits of a string in javascript. For more information, please follow other related articles on the PHP Chinese website!