![]() The findIndex() method works the same way as find() method except find() returns the first matched element and findIndex() returns the index of the first matched element. This method also takes a function argument which returns true or false. The Array findIndex() method returns the index of first matched element in array that satisfies a condition. let score = let value = score.find(val => val > 60) // returns the first element that passed the condition console.log(value) // 73 The findIndex() method If no element passed the condition then find() method will return undefined. If the function returns true for any element then that element will be returned by the find() method and it stops checking further for rest of the elements. The find() method executes this function for each element of array. The find() method takes a function as argument which returns true or false based on some condition. The Array find() method returns the first matched element in array that satisfies a condition. The various methods are find, findIndex, includes, indexOf, lastIndexOf and loops ( for, filter, map). We will be discussing about 6 ways to find in array. whether we are searching for element or its position in the array. But we can always choose the method that satisfies our search criteria i.e. ![]() ![]() There are various methods available to find elements or their positions in Array. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |