Finding


After ES 2017

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

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


Before ES 2017

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

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


indexOf



lastIndexOf



find



findIndex




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