Home > Web Front-end > JS Tutorial > body text

How to use js split method

coldplay.xixi
Release: 2020-09-11 14:50:17
Original
10326 people have browsed it

Usage of js split method: The split method is used to split a string into a string array. The syntax is [stringObject.split(separator,howmany)], where the separator parameter is required and the howmany parameter is optional. select.

How to use js split method

Related learning recommendations: javascript video tutorial

split() method is processed in js String is a very common and important method that must be mastered.

split() method is used to split a string into characters string array.

Syntax

stringObject.split(separator,howmany)
Copy after login

Parameter description

  • separator Parameters: required. A string or regular expression to split the stringObject from where specified by this parameter.

  • howmanyParameters: Optional. This parameter specifies the maximum length of the returned array. If this parameter is set, no more substrings will be returned than the array specified by this parameter. If this parameter is not set, the entire string will be split regardless of its length.

For specific usage, see the following code

1,

        
Copy after login

2,

"2:3:4:5".split(":")    
//将返回["2", "3", "4", "5"]
"|a|b|c".split("|") 
//将返回["", "a", "b", "c"]
Copy after login

3,

"hello".split("")   
//可返回 ["h", "e", "l", "l", "o"],分割单词
"hello".split("", 3)    
//可返回 ["h", "e", "l"],取单词前三个字母
Copy after login

The above is the detailed content of How to use js split method. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!