1. 程式人生 > >判斷數組裡面的下標是否等於一個字串

判斷數組裡面的下標是否等於一個字串

使用includes() 

1、判斷字串裡面是否包含一個字串

示例:

    var a = 'aaaaaaaav'
    console.log(a.includes('v'));    //true

    var a = 'aaaaaaaav'
    console.log(a.includes('c'));    //false

    var a = 'aaaaaaaav'
    console.log(a.includes('aaa'));    //true

2.判斷一個字串是否等於陣列的下標

示例:

let arr=['a', 'b', 'cc', 'ddd'];
console.log(arr.includes('a'));   true
console.log(arr.includes('cc'));   true
console.log(arr.includes('c'));   false
console.log(arr.includes('e'));   false