.findIndex()是JavaScript中的高阶函数吗? [英] Is .findIndex() a Higher Order Function in JavaScript?
问题描述
我基本上了解 .filter()
, .reduce()
和 .map()
是高阶函数,因为它们将其他函数作为参数,例如:
Basically I understand that .filter()
, .reduce()
, and .map()
are higher-order functions because they take other functions as their arguments, like this:
arrayOfWords.filter(words => words.length> 6);
unflattenedArray.reduce((accumulator,currentValue)=>累加器+ currentValue);
arrayOfIntegers.map(x => x * 2);
那么 .findIndex()
也是一个高阶函数吗?
So then is .findIndex()
also a higher-order function?
似乎可以像其他方式一样操作:
Seems to operate just like the others:
let fruits = ["apple", "banana", "cantaloupe", "blueberries", "grapefruit"];
let index = fruits.findIndex(fruit => fruit === "blueberries");
推荐答案
是的,正确的是 findIndex
是一个高阶函数.
Yes, that is correct, findIndex
is a higher-order function.
findIndex()
方法返回满足提供的测试功能的数组中第一个元素的索引.否则,它返回-1,表示没有元素通过测试.
The findIndex()
method returns the index of the first element in the array that satisfies the provided testing function. Otherwise, it returns -1, indicating no element passed the test.
https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/Array/findIndex
这篇关于.findIndex()是JavaScript中的高阶函数吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!