for...of
for(let val of xxx) {
console.log(val)
}
用于遍历数组,字符串,元素列表,类数组对象,es6 新增 Map Set
比较
for of
纯数字与类数组集合均可遍历
for in
用于数组与对象,获取的是key
forEach
用于纯数组
新增字符串操作
1.模板字符串
就是反引号的用法,定义比较长,复杂的字符串,可以插入变量,可以插入函数
2.repeat()
console.log("abc".repeat(10));
3.字符串补全长度
let str = "hello";
console.log(str.padStart(10))
console.log(str.padStart(10,"*"))
console.log(str.padStart(10,"abc"))
str.padEnd()
4.包含某个子字符串
之前
indexOf,正则
str.includes()
判断字符串是否包含指定的子串
str.startsWidth()
判断当前字符串是否以另一个字符串作为开头
str.endsWidth()
判断当前字符串是否以另一个字符串结尾