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!