Home > Web Front-end > JS Tutorial > The difference between split and join in JavaScript

The difference between split and join in JavaScript

angryTom
Release: 2020-02-14 13:22:47
Original
4048 people have browsed it

The difference between split and join in JavaScript

The difference between split and join in JavaScript

1. split() is used to split strings , returns an array

For example:

var string=“hello world?name=xiaobai”;
var splitString = string.split("?");
console.log(splitString);//["hello world","name=xiaobai"]
Copy after login

split() has only one parameter: split string or regular expression; when there are two parameters, the second parameter refers to The number of elements in the returned array;

2. join() is used to connect multiple characters or strings, and the return value is a string

For example:

var arr= new Array();
arr[0]="hello";
arr[1]="xiao";
arr[2]= "bai";
arr.join("&");//"hello&xiao&bai"
join();//默认分割符为逗号;
Copy after login

This article comes from the js tutorial column, welcome to learn!

The above is the detailed content of The difference between split and join in JavaScript. 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