vuvivian's blog

越努力,越幸运.

http://c.biancheng.net/view/5673.html

  1. toString()
    1
    2
    3
    4
    var a = [1,2,3,4,5,6,7,8,9,0];  //定义数组
    var s = a.toString(); //把数组转换为字符串
    console.log(s); //返回字符串“1,2,3,4,5,6,7,8,9,0”
    console.log(typeof s); //返回字符串string,说明是字符串类型
1
2
3
4
5
var a = [1,2,3,4,5,6,7,8,9,0];  //定义数组
var b = [1,2,3,4,5,6,7,8,9,0]; //定义数组
var s = a + b; //数组连接操作
console.log(s); //返回“1,2,3,4,5,6,7,8,9,01,2,3,4,5,6,7,8,9,0”
console.log(typeof s); //返回字符串string,说明是字符串类型
1
2
3
var a = [1,[2,3],[4,5]],[6,[7,[8,9],0]]];  //定义多维数组
var s = a.toString(); //把数组转换为字符串
console.log(S); //返回字符串“1,2,3,4,5,6,7,8,9,0”
1
2
3
var a = [1,2,3,4,5];  //定义数组
var s = a.toLocalString(); //把数组转换为本地字符串
console.log(s); //返回字符串“1,2,3,4,5,6,7,8,9,0”
  1. join()

    1
    2
    3
    	var a = [1,2,3,4,5];  //定义数组
    var s = a.join("=="); //指定分隔符
    console.log(s); //返回字符串“1==2==3==4==5”
  2. split()

    1
    2
    3
    4
    	var s = "1==2== 3==4 ==5";
    var a = s.split("==");
    console.log(a);
    console.log(a.constructor == Array);
本文最后更新于 天前,文中所描述的信息可能已发生改变