ES 6中判断字符串是否为子串的一个方法

以前javascript中判断子串,就用indexof了,比如:
 

  var str = "test";
        if (str.indexOf('te') > -1) { 
            console.log('match') 
        } else {
            console.log('not found')
        }

ES6中,用include就可以了:
 

 var str = "test";
        console.log(str.includes('te')); //true

猜你喜欢

转载自blog.csdn.net/jackyrongvip/article/details/88852631
今日推荐