Home > Web Front-end > JS Tutorial > Summary of methods for manipulating strings in JS

Summary of methods for manipulating strings in JS

巴扎黑
Release: 2017-07-18 15:49:11
Original
1155 people have browsed it

1: concat() combines two or more characters of text and returns a new string

1 var f1 ="hello";
2 var f2="world";
3 document.write(f1.concat(f2)) //hello world

2:indexof() Returns the index of the first occurrence of a substring in the string. If there is no match, returns -1

##1var f3="hello world"2 console.log(f3.indexOf('world')) //63console.log(f3.indexOf(' World')) //-14##Note
##console.log(f3.indexOf('hello')) / /0
: index

Of is case sensitive

3:charAt() – Returns the character at the specified position.

1var f4="hello world";2console.log(f4.charAt(1)) //e3console.log(f4) //hello world
4:lastIndexOf() method can return the last occurrence position of a specified string value, and search from back to front at the specified position in a string .

1var f3="hello world"2console. log(f3.lastIndexOf('world')) //6console.log(f3.lastIndexOf('World')) / /-1console.log(f3.lastIndexOf('hello')) //05:substring() – Returns a substring of a string. The parameters passed in are the starting position and the ending position (not required). Note: The parameter cannot be a negative number
##3
4

##1

var f5="hello world"2console.log(f5.substring(3)) //lo world3console.log(f5.substring(3,8) ) //lo wo7:replace() – Used to find a string that matches a regular expression, and then replace the matching string with a new string.
6:match() – Checks whether a string matches a regular expression.
8:search() – Perform a regular expression matching search. If the search is successful, the matching index value in the string is returned. Otherwise, -1 is returned.​

9:slice() – Extract a part of the string and return a new string. (The parameter can be a negative number)

##1

var f6="hello world"#10: split() – method is used to split a string into an array of strings.
2 console.log(f6.slice(6)) //world
3 console.log(f6.slice(6,9)) //wor
1

var f7="hello world";11:toLowerCase() – Convert the entire string to lowercase letters.  
2 console .log(f7.split("")); //["h", "e", "l", "l", "o", " ", "w", "o", "r", "l", "d"]
3 console.log(f7.split(" ")); //["hello", "world" ]
4 console.log(f7.split(" ",1)); //["hello"]
12:toUpperCase() – Convert the entire string to uppercase letters.
 

The above is the detailed content of Summary of methods for manipulating strings in JS. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
What are JavaScript hook functions?
From 1970-01-01 08:00:00
0
0
0
What is JavaScript garbage collection?
From 1970-01-01 08:00:00
0
0
0
c++ calls javascript
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template