拼接字符串的几个常用方法
2023-03-14 本文已影响0人
小睿同学
- 最常用的加号运算符
let date='2023-03-15',
let time='17:50'
console.log(date+' '+time) //2023-03-15 17:50
2.es6的反引号``
let date='2023-03-15',
let time='17:50'
console.log(`${date} ${time}`) //2023-03-15 17:50
3.兼容好点的es5(concate)
let date='2023-03-15',
let time='17:50'
console.log(date.concat(' ', time)) //2023-03-15 17:50
- 数组的join
let date='2023-03-15',
let time='17:50'
console.log([date, time].join(' ')) //2023-03-15 17:50