Js——String object

Table of contents

1. String object

Second, the creation of String

3. Common methods of String

1. length string length

2. charAt(index) returns the character at the specified position 

3. indexOf(character) returns the index of the position of the character

4. concat() connection string 

 5. replace() replace

6. split() splits a string into an array of strings

7. indexOf() Returns the last occurrence of a specified string value

8. includes( ) Determine whether the string contains characters turn and return false

9、match()


1. String object

StringThe global object is a constructor function for a string or a sequence of characters, a string can use single quotes or double quotes.

Second, the creation of String


3. Common methods of String

1. length string length


2. charAt(index) returns the character at the specified position 

If no index is given, it defaults to 0. If the given index exceeds the maximum value of the index, or is less than 0, an empty string will be returned.


3. indexOf(character) returns the index of the position of the character

The index here also starts from zero, and the index of the last digit is str.length-1. If the searched element does not exist, -1 will be returned


4. concat() connection string 

Combines two strings into one new string


 5. replace() replace

Two parameters are required, one is the value to be replaced (it can be a string or a regular expression), and the second parameter is the value to be replaced (it can be a string or a Callback)


6. split() splits a string into an array of strings

Use a specified split string to determine the position of each split


7. indexOf() Returns the last occurrence of a specified string value

The index here also starts from zero, and the index of the last digit is str.length-1. If the searched element does not exist, -1 will be returned


8. includes( ) Determine whether the string contains characters turn and return false


9、match() 

Used to query whether the string is contained, and return the string if it is contained

Guess you like

Origin blog.csdn.net/weixin_68485297/article/details/124430641