🌺前言
你不知道的模板字符串
javascript
function customTag(strings, ...values) {
console.log(strings,values);// ["Name: ",", Age: ",""] ["Alice",30]
let result = "";
strings.forEach((string, index) => {
result += string;
if (index < values.length) {
result += values[index];
}
});
return result.toUpperCase();
}
const name = "Alice";
const age = 30;
const formattedString = customTag`Name: ${name}, Age: ${age}`;
console.log(formattedString); // 输出 "NAME: ALICE, AGE: 30"
文章最后更新于 2024-11-15 17:24:52
作者:徐徐版权声明:转载请注明文章出处
留言

~~空空如也