Array.prototype.findIndex() in JavaScript ES6

preview_player
Показать описание
#shorts #javascript #es6 #findIndex
The findIndex() method returns the index of the first element in an array that satisfies the provided testing function. If no elements satisfy the testing function, -1 is returned.

The findIndex() method executes the callbackFn function once for every index in the array, in ascending order, until it finds the one where callbackFn returns a truthy value.

If such an element is found, findIndex() immediately returns the element's index. If callbackFn never returns a truthy value (or the array's length is 0), findIndex() returns -1.

The range of elements processed by findIndex() is set before the first invocation of callbackFn. Elements that are assigned to indexes already visited, or to indexes outside the range, will not be visited by callbackFn. callbackFn will not process the elements appended to the array after the call to findIndex() begins. If an existing, unvisited element of the array is changed by callbackFn, its value passed to the callbackFn will be the value at the time findIndex() visits the element's index. Elements that are deleted are still visited.

== Social Media ==
Рекомендации по теме