The best JavaScript String (String) objects Tutorial In 2024, In this tutorial you can learn JavaScript strings,Examples,Examples,Examples,Examples,String (String),Examples,Find a string in a string,Examples,Content Match,Examples,Replace the contents,Examples,String case conversion,Examples,String to an array,Examples,Special characters,String properties and methods,
String object is used to handle the existing character block.
A string is used to store a series of characters like "John Doe".
A string can use single or double quotes:
You use the position (index) can access any of the string of characters:
The zero-based index of the string, the first string of characters [0], the second character is [1], and so on.
You can use quotation marks in the string, the following examples:
Or you can use the escape character in a string using quotation marks:
String (String) using the length property length to calculate the length of the string:
Use string indexOf () to locate the position of a string in a specified character first appears:
If you do not find the corresponding character function returns -1
lastIndexOf () method to find the location at the end of the beginning of the string occurrences.
match () function is used to find a particular string of characters, and if found, then return to this character.
replace () method replaces some characters with some of the characters in a string.
String case conversion using the function toUpperCase () / toLowerCase ():
Use string split () function into an array:
Javascript can use the backslash (\) to insert special characters, such as: other special symbols apostrophes, quotes and so on.
See the following JavaScript code:
In JavaScript, strings start and stop the use of single or double quotes. This means that the string above will be cut: We are the so-called
Solve the above problems can use the backslash escape quotes:
JavaScript will output the proper text string: We are the so-called "Vikings" from the north.
The following table lists other special characters, you can use the backslash escape special characters:
Code | Export |
---|---|
\ ' | apostrophe |
\ " | Double quotes |
\\ | Diagonal rod |
\ N | Wrap |
\ R | Enter |
\ T | tab |
\ B | Blank |
\ F | PAGE |
Attributes:
method: