var s1 = "abc" , s2 = "def"; console.log(s1 + s2); //返回字符串“abcdef”
var s1 = "abc"; var s2 = s1.concat("d" , "e" , "f"); //调用concat()连接字符串 console.log(s2); //返回字符串“abcdef”concat() 方法不会修改原字符串的值,与数组的 concat() 方法操作相似。
var s = "JavaScript" , a = []; for (var i = 0; i < 1000; i ++) { a.push(s); var str = a.join(""); a = null; document.write(str);在上面示例中,使用 for 语句把 1000 个 “JavaScript”字符串装入数组,然后调用数组的 join() 方法把元素的值连接成一个长长的字符串。使用完毕应该立即清除数组,避免占用系统资源。
Copyright © 广州京杭网络科技有限公司 2005-2025 版权所有 粤ICP备16019765号
广州京杭网络科技有限公司 版权所有