数组转字符串
b = a.join('-'); //a-b-c-d-e 使用-拼接数组元素
c = a.join(''); //abcde
字符串转数组
实现方法为将字符串按某个字符切割成若干个字符串,并以数组形式返回,示例代码如下:
var str = 'ab+c+de';
var a = str.split('+'); // [ab, c, de]
var b = str.split(''); //[a, b, +, c, +, d, e]
去处字符串最后一个逗号
首先我们得判断字符串最后一位是不是逗号(如果是那么我们切割它,如果不是那岂不是切坏了······)
if(a[a.length-1] == ","){
a=a.substring(0,a.length-1);
}else{
a=a;
}
扫描二维码关注公众号,回复:
2978508 查看本文章