Javascript method to remove the first two digits of a string: 1. Use the slice() function, the syntax "string.slice(2)"; 2. Use the substring() function, the syntax "string.substring(2)" ".
The operating environment of this tutorial: windows7 system, javascript version 1.8.5, Dell G3 computer.
javascript removes the first two digits of the string
Method 1: Use the slice() function
## The #slice(start, end) method extracts a portion of a string and returns the extracted portion as a new string. Use the start (inclusive) and end (exclusive) parameters to specify the part of the string to extract.var str="ab12345"; console.log(str.slice(2)) // => 12345
Method 2: Use substring() function
The substring(from, to) method is used to extract characters between two specified subscripts in a string. The substring() method returns a substring that includes the characters at the beginning, but does not include the characters at the end. Example:var str="ab12345"; console.log(str.substring(2)) // => 12345
The above is the detailed content of How to remove the first two digits of a string in javascript. For more information, please follow other related articles on the PHP Chinese website!