1.字符串查找
属性 | 作用 | 返回类型 | 使用 |
---|---|---|---|
startsWith | 查找字符串是否以指定的子字符串开始 | boolean | str.startsWith(‘str’) |
endsWith | 查找字符串是否以指定的子字符串结束 | boolean | str.startsWith(‘str’) |
includes | 查找字符串中是否包含指定字符串 | boolean | str.startsWith(‘str’) |
1.模板字符串的高级用法
可以使用自定义函数处理模板字符串, say `hello, my name is ${name}` (say = function)
const name = '儿子';
// 自定义函数 say
function say(str, name) {
console.log(str, name) // str = ['hello, my name is ', ''] name = 儿子
return str[0] + '爸爸'
}
const str = say `hello, my name is ${name}`
console.log(str) // hello,my name is 爸爸