ES6 新增的字符串方法

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/TIAN20121221/article/details/79404291

在ES5中判断一个字符串中是否含有某个字符串一般都是这样:
console.log(‘YO’.indexof(‘Y’)!==-1)

现在提供了语义话的方法:
YO.includes(‘Y’);
YO.startWith(‘Y’);
YO.endsWith(‘O’);
YO.repeat(‘次数’);重复YO多少次!

猜你喜欢

转载自blog.csdn.net/TIAN20121221/article/details/79404291
今日推荐