字符串扩展

 
1. contains(str) : 判断是否包含指定的字符串
2. startsWith(str) : 判断是否以指定字符串开头
3. endsWith(str) : 判断是否以指定字符串结尾
4. repeat(count) : 重复指定次数
5. 模板字符串 : 简化字符串的拼接


console.log("atguigu".indexOf("gu"));
console.log("atguigu".indexOf("gug")); //indexof是ES5

//console.log('atguigu'.contains('gu')); //true //chrome不支持, 但firefox支持
// console.log('atguigu'.contains('gug')); //false


console.log('atguigu'.startsWith('at')); //true
console.log('atguigu'.startsWith('ata')); //false

console.log('atguigu'.endsWith('at')); //false
console.log('atguigu'.endsWith('gu')); //true

console.log('atguigu'.repeat(3)); //atguiguatguiguatguigu


var name = 'Jack';
var age = 12;
console.log("我叫"+name+",10年后我年方"+(age+10)); //拼字符串
console.log(`我叫${name},10年后我年方${age+10}`); //模板字符串(注意引号,是Esc下面的符号)
posted @ 2016-07-12 15:48  学习呗!  阅读(141)  评论(0编辑  收藏  举报