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

The difference between split and join in JavaScript

angryTom
angryTomOriginal
2020-02-14 13:22:474020browse

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"]

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();//默认分割符为逗号;

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!

Statement:
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