includes

Added in ES 2017 / ECMAScript 6
The Array.prototype.includes()
This method is used to find out whether the element is included in the array or not.


const myArray = ['Mon', 'Tue', 'Wed'];  
arrayContains(myArray, 'Tue'); // true

function arrayContains(theArray, searchValue) {
   return theArray.includes(searchValue);
}

This method takes 2 parameters
valueToFind - the value to find
fromIndex - which index to start the search from



Before ES 2017

const myArray = ['Mon', 'Tue', 'Wed'];  
arrayContains(myArray, 'Tue'); // true

function displayDay(theArray, searchValue) {
   return theArray.indexOf(searchValue) > -1;
}




© 2022 Better Solutions Limited. All Rights Reserved. © 2022 Better Solutions Limited TopPrevNext