将数组转化为字符串:join()&toString()

    var a = [ "David", "Cynthia", "Raymond", "Clayton", "Mike", "Jennifer" ];
    var a1 = a.join();
    alert(a1); // David,Cynthia,Raymond,Clayton,Mike,Jennifer
    alert(typeof a1)//string
    a2 = a.toString();
    alert(a2); // David,Cynthia,Raymond,Clayton,Mike,Jennifer
    alert(typeof a2);//string

 补充:join()方法的另一种运用:

    var a = [ "David", "Cynthia", "Raymond", "Clayton", "Mike", "Jennifer" ];
    var a1 = a.join("-****-");
    document.write(a1); // David-****-Cynthia-****-Raymond-****-Clayton-****-Mike-****-Jennifer 

 

posted @ 2016-04-08 19:16  绯乐  阅读(2012)  评论(0编辑  收藏  举报