将数组转化为字符串: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