JavaScript string methods include: 1. indexOf method, finds whether a string contains a certain substring, and returns the position where the substring appears; 2. replace method, replaces certain characters in the string is a new character; 3. The split method will separate the string into an array according to the provided delimiter.
JavaScript string methods are:
1. First, let’s introduce the commonly used indexOf method. This method mainly It is used to find whether a string contains a certain substring. It returns the position where this substring appears. If it appears at the beginning of the string, it returns 0. If it does not include the substring, it returns -1.
#2. Another commonly used method is the replace method, which replaces certain characters in the string with new characters.
#3. The split method is also one of the more commonly used methods. It will separate the string into an array according to the provided delimiter.
4. The substring method can intercept part of the characters of the string. The parameters are the starting position and the stopping position. The code in the picture below starts from the fifth position and intercepts to the ninth position.
#5. When you are dealing with English characters, the toLowerCase method is also commonly used, which is to change all characters to lowercase characters.
6. Compared with toLowerCase, the toUpperCase method is to change all characters to uppercase characters.
#7. There are other methods for strings, but they are relatively less commonly used. If you want to know more about them, you can check the JS help documentation.
Related learning recommendations: javascript video tutorial
The above is the detailed content of What are the JavaScript string methods?. For more information, please follow other related articles on the PHP Chinese website!