數組和字符串之間的相互轉換

1.數組       轉      字符串

var a, b;
    a = new Array('a','b','c','d','e');
    b = a.join("-");
    document.write(b);
    document.write(typeof a);
    document.write(typeof b);
<span style="font-family: Verdana, Arial, 宋體; line-height: 18px; background-color: rgb(249, 249, 249);">join() 方法用於把數組中的所有元素放入一個字符串。</span>
2.字符串    轉    數組

var s = "abc,abcd,aaa";
    ss = s.split(",");// 在每個逗號(,)處進行分解。
    document.write(ss);
    document.write(typeof ss);
    document.write(typeof s);
<span style="font-family: Verdana, Arial, 宋體; line-height: 18px; background-color: rgb(249, 249, 249);">split() 方法用於把一個字符串分割成字符串數組。</span>



發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章