Javascript字符串拼接三种方法比较

let name = "张三";
let tel = "13800000000";
let address = "浙江省杭州市西湖区北山街1号";

方法1:加号拼接法

let str1 = "姓名:" + name + "," + "电话:" + tel + "," + "地址:" + address;

方法2:replace替换法

let str2 = "姓名:{name},电话:{tel},地址:{address}".replace("{name}", name).replace("{tel}", tel).replace("{address}", address);

方法3:ES6模板字符串

let str3 = `姓名:${name},电话:${tel},地址:${address}`;


评论: 0 | 引用: 0 | 查看次数: 1124
发表评论
登录后再发表评论!