内容目录
concat()函数用于将当前字符串与指定字符串进行拼接,并返回拼接后的字符串。
该函数属于String对象,所有主流浏览器均支持该函数。
语法
stringObject.concat( str1 [, str2 [, str... ]] )
参数
| 参数 | 描述 |
|---|---|
| str1 | String类型指定的字符串1。 |
| str2 | 可选/String类型指定的字符串2。 |
| str | 可选/String类型指定的字符串项,可以有多个。 |
返回值
concat()函数的返回值为String类型,其返回值为拼接后的字符串。
concat()函数的作用等同于运算符+
,例如:str.concat(str1, str2)等同于str + str1 + str2。
示例&说明
var str = "CodePlayer";
str = str.concat(",https://codeplayer.vip");
document.writeln( str ); // CodePlayer,https://codeplayer.vip
str += ",Play";
document.writeln( str ); // CodePlayer,https://codeplayer.vip,Play
str = str.concat(",a", ",b", true);
document.writeln( str ); // CodePlayer,https://codeplayer.vip,Play,a,btrue

0 条评论
撰写评论