The operation of reading strings used in the learning process

    In the process of learning Javascript, I used some operations on strings, and now I will make a small summary.
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

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=327042019&siteId=291194637