node.js 怎么拼接字符串

如题所述

第一种    "+" 运算符

var str1 = 'a',

    str2 = 'b';

var str3 = str1 + str2 + 'c';

console.log( str3 ); // output 'abc'


 第二种    数组的 join 方法:

var str1 = 'a',
    
    str2 = 'b';

var str3 = [ str1, str2, 'c' ].join( '' );

console.log( str3 ); // output 'abc'


第三种    字符串模板(ES6):

var str1 = 'a',

    str2 = 'b';

var str3 = `${str1}${str2}c`;

console.log( str3 ); // output 'abc'

温馨提示:答案为网友推荐,仅供参考