1、字符串Unicode表示法
console.log("\u0061");
2、字符串遍历器接口,for of
<script>
let str = 'abcdefg';
for(let i=0;i<str.length;i++){
console.log(str[i]);
}
for (let s of str) {
console.log(s);
}
</script>
3、模板字符串方法
<body>
<div id="contianer"></div>
<div id="contianer2"></div>
<script>
//es5字符串拼接方法
var a;
var href = "https://baidu.com";
var text = "百度";
a = "<a href='"+href+"'>"+text+"</a>";
console.log(a);
var contianer = document.getElementById("contianer");
contianer.innerHTML = a;
//es6字符串模板方法
let aa = `<a href='${href}'>${text}</a>`
var contianer2 = document.getElementById("contianer2");
contianer2.innerHTML = aa;
</script>
</body>
4、字符包含、以某字符开头、结尾方法
<script>
let str = 'abcdefg';
//只有一个参数时
console.log(str.includes('abc')); //true
console.log(str.startsWith('abc')); //true
console.log(str.endsWith('fg')); //true
//添加第二个参数时代表是从那个下标位置开始搜索
console.log(str.includes('abc',2)); //false
console.log(str.startsWith('def',3)); //true
console.log(str.endsWith('abcde',5)); //true
</script>
5、字符重复、字符补全
<script>
let str = 'a';
console.log(str.repeat(2));
console.log(str.padStart(10,"12345"));
console.log(str.padEnd(10,"123"));
</script>
6、空格去除
<script>
let str = ' A ';
console.log(str.trim());
console.log(str.trimStart());
console.log(str.trimEnd());
</script>
7、指定获取某个下标的字符
<script>
let str = 'abcdefg';
console.log(str.at(1));
console.log(str.charAt(1));
</script>