A: Declaration of the object
var stringobject new String ("Hello word"); var stringobjectb
Properties of the B:stringobject
Stringobject.length, string length (spaces are also placeholders), and corresponding, can be accessed by string[n] to access the characters of the string with the corner labeled N
var str = "Today is good Today"; Console.log (str.length); //19Console.log (str[2]); // D
String Method ↓
C: Single-character access
CharAt (n), passing in numeric value, returning the corresponding character in that position
charCodeAt (n), passing in numeric value, returns the position corresponding to the character encoding
var str = "Dashu yang"; Console.log (Str.charat (2)); // SConsole.log (Str.charcodeat (2)); // the
D:slice (n), string intercept, accept one or two values
var str = "Dashu yang"; Console.log (Str.slice (2)); // Shu Yangconsole.log (Str.slice (2,5)); // Shu // ng = = Console.log (Str.slice (str.length-2))
E:indexof (), character position, passed in string, returns the location of the string, and if no 1 is returned, the second argument can be passed, indicating where to start the search
var str = "Dashu yang"; Console.log (Str.slice (' a ')); // 1console.log (Str.slice (' as ')); // 1console.log (str.slice (' X ')); // -1console.log (Str.slice (' A ', 3)); //
F:match (); a pattern-matching method for a string that receives a regular expression or RegExp object, returning an array
var text = "Cat,bat,sat,fat"=/.at/; var matches = Text.match (pattern); // Same as Pattern.exec (text) Console.log (matches);//catconsole.log (matches[0]);//cat
E:replace (), string substitution, receive two parameters, first argument is a string or regular expression, the second argument is a string or a function, returns a string
var text = "Cat,bat,sat,fat", Console.log (Text.replace (' Ca ', ' 123 ')); 123t,bat,sat,fatconsole.log (Text.replace (/at/g, ' 123 ')); // c123,b123,s123,f123
F:split (), string split, receive one or two arguments, the first string or regular expression, the second is the maximum length of the returned array, the return value is an array
var text = "Cat,bat,sat,fat"; Console.log (Text.split (', ')); ["Cat", "bat", "sat", "fat"]console.log (Text.split (', ', ' 3 ')); // ["Cat", "bat", "sat"]Console.log (Text.split (/at/,)); // ["C", ", B", ", S", ", F", "" ")
JS Basics Comb---String object