1. Character Methods: charAt (), charCodeAt (), fromCharCode ()
1 var stringValue = "hello world ";
2 alert (stringValue. charAt (1); // "e"
3 alert (stringValue [1]); // "e"
4 alert (stringValue. charCodeAt (1); // 101
5 alert (String. fromCharCode (104,101); // "he" 2. Return the substring method slice (), substr (), substring ()
The first parameter of slice () and substring () methods indicates the starting position of the stator string, and the second parameter specifies the settlement position (excluding the Ending position). The original string remains unchanged.
The second parameter of substr () indicates the number of returned characters. The original string remains unchanged.
1 var stringValue = "hello world ";
2 alert (stringValue. slice (3); // "lo world"
3 alert (stringValue. substring (3); // "lo world"
4 alert (stringValue. substr (3); // "lo world"
5 alert (stringValue. slice (3, 7); // "lo w"
6 alert (stringValue. subtring (3,7); // "lo w"
7 alert (stringValue. substr (3, 7); // "lo worl"
8
9 alert (stringValue. slice (-3); // "rld", takes the last three characters of the array
10 alert (stringValue. slice (-3); // "rld", takes the last three characters of the array
3. String Location Methods indexOf () and lastIndexOf ()
The indexOf () method searches for substrings from and to the backend. It can receive one or two parameters. The first parameter specifies the substrings to be searched, and the second parameter specifies to search back from this position, -1 not found
The lastIndexOf () method searches forward and backward for a substring. It can receive one or two parameters. The first parameter specifies the substring to be searched, and the second parameter specifies to search forward from this position, -1 not found
1 var stringValue = "hello world ";
2 alert (stringValue. indexOf ("o"); // 4
3 alert (stringValue. lastIndexOf ("o"); // 7
4 alert (stringValue. indexOf ("o", 6); // 7
5 alert (stringValue. lastIndexOf ("o", 6); // 44. String case-insensitive conversion methods toLowerCase () and toUpperCase ()
ToLowerCase () to lowercase, toUpperCase () to uppercase
5. Comparison of strings localeCompare ()
LocaleCompare () can be English or Chinese, with uppercase letters followed by lowercase letters
6. String sorting:
1 var stringValue = ["China", "Nan", "Jun"];
2 alert (stringValue. sort (stringCompare ));
3 // Ascending Order Function a-z
4 function stringCompare (value1, value2 ){
5 return value1.localeCompare (value2); // in descending order z-a, value1 and value2 interchange locations
6}
From Sunday walk