The search string
var string = 'abcdef'; console.log(string.indexOf('b'));
Search for a string. If the return value is -1, it means that there is no string to be searched. If there is a string to be searched, it returns the position of the original character of the string.
E.g:
var string='abcdef'; console.log(string.indexOf('b')); // return value is 1 console.log(string.indexOf('d')); // return value is 3
Second, intercept the string
var string = 'abcdef'; console.log(string.substring(0,1)); console.log(string.substring(3));
The substring method will return a string containing the substring from start to the end (excluding end).
For example :
var string = 'abcdef'; console.log(string.substring(0,1)); // return value is a console.log(string.substring(3)); //The return value is def console.log(string.substring(2,4)); //The return value is cd console.log(string.substring(0)); //The return value is abcdef