Array.includes()

Array.prototype.includes()

Suboor Khan
Suboor Khan

Suboor Khan

Software Engineer

JavascriptTypescript

The includes() method determines whether an array includes a certain value among its entries, returning true or false as appropriate.



JavaScript Demo: Array.includes()


   
       const array1 = [1, 2, 3];
        console.log(array1.includes(2));
        // expected output: true
        
        const pets = ['cat', 'dog', 'bat'];
        
        console.log(pets.includes('cat'));
        // expected output: true
        
        console.log(pets.includes('at'));
        // expected output: false
    
inArray returns the index of the element in the array, not a boolean indicating if the item exists in the array. If the element was not found, -1 will be returned.
HomeNews feedsWorkSessionsContact