Javascript intercepts the specified string from the right in three ways


Intercept fg to the right of abcdefg

Methods a

< Script> String = “abcdefg” Alert (string, the substring (string length 2, the string. Length)) < / script>

Method 2

< Script> Alert (” abcdefg ”. The match (/. * (. {2}) /) [1]) < / script>

< Script> Alert (” abcdefg ”. The match (/. {2} $/)) < / script>

Methods 3

< Script> Alert (” abcdefg ”. Slice (-) 2)   // this one is recommended. It is relatively simple. -2 means to take the two characters on the right < / script>