字符串includes,startsWith,endsWith方法测试
普通的用法:
var str = 'Hello';
console.log(str.indexOf('o')); // 4
console.log(str.includes('e')); // true
console.log(str.startsWith('H')); // true
console.log(str.endsWith('e')); // false
添加第二个参数之后,标注查询的起始位置:
var str = 'Hello';
console.log(str.includes('e',1)); // true
console.log(str.startsWith('e',1)); // true
console.log(str.endsWith('l',3)); // true
实用的repeat方法
var str = 'Hello';
var res = str.repeat(3);
console.log(res); // HelloHelloHello