Home > Web Front-end > JS Tutorial > How to use split function

How to use split function

不言
Release: 2019-01-26 15:31:38
Original
13089 people have browsed it

split function can be used to split a string and return it as a new array, we will use split function to separate the array by space character, the space character we mentioned will be our separator which is used by split function How to decompose a string.

How to use split function

Basic syntax of the split function

string.split([separator][, limit]);
Copy after login

separator indicates the character specified to separate the string. If the separator is omitted, the returned array contains one element consisting of the entire string.

limit indicates 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.

Additionally, when the string is empty, split returns an array containing an empty string instead of an empty array.

Given an empty argument, split() will create a comma-separated array for each character in the string.

Let’s look at a specific example

The code is as follows

<!DOCTYPE html>
<html>
<head>
	<title></title>
</head>
<body>
<script type="text/javascript">
const originalString = "How are you?";
const splitString = originalString.split(" ");
console.log(splitString);
</script>
</body>
</html>
Copy after login

The effect is as follows

How to use split function

This article ends here That’s all over. For more exciting content, you can pay attention to the relevant column tutorials on the PHP Chinese website! ! !

The above is the detailed content of How to use split function. 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