字符串模板
let datas = { name: "tales", age: 27 } let str = `我是${datas.name}, 我今年${datas.age}岁`; console.log(str);
字符串查找 (includes->返回true/false indexOf->返回索引的位置)
let str = "apple ksone tales"; let res = str.includes("ksone"); console.log(res); //true
字符串是否以谁开头
let str = "apple ksone tales"; let res = str.startsWith("apple"); console.log(res); //true
字符串是否以谁结尾
let str = "apple ksone tales"; let res = str.endsWith("tales"); console.log(res); // true
字符串重复
let str = 'tales'; let res = str.repeat(3); console.log(res); // talestalestales
字符串填充
let str = 'a'; let padStr = 'xxx'; let res = str.padStart(str.length+padStr.length, 'xxx'); console.log(res); // xxxa let res = str.padEnd(str.length+padStr.length, 'xxx'); console.log(res); // axxx