let str="wbiokr";
str.repeat(2);//wbiokrwbiokr"str被重复了2次返回,str不改变'hi'.repeat(3);//"hihihi"'hi'.repeat(2.6);//'hihi'浮点类型参数,会取整重复'hi'.repeat(0);//''0的时候返回空字符串'hi'.repeat(-3)//负数,报错'hi'.repeat(undefined)//''undefined转化为0'hi'.repeat(null)//''null转化为0'hi'.repeat(NaN)//''NaN转化为0
string.repeat(num)方法,参数num为重复字符串的次数,各种情况下的返回值见代码。
‘${}’:
let str="wbiokr";
$('#box').html('
there is a word ${str},i know it
');
//there is a word wbiokr,i know it
ES6为js新增了很多方法,包括遍历、查询、替换等等,可以很简洁的替换ES5中的类似方法,本文不考虑codePointAt等不常用方法。for…of:let str="wbiokr";for(let s of str){ console.log(s)}//结果:w, b, i, o, k, r由于es5并没有为js制定字符串相关遍历方法,for…of无疑会是接下来前端开发中的一个很