.findIndex()是JavaScript中的高阶函数吗? [英] Is .findIndex() a Higher Order Function in JavaScript?

查看:40
本文介绍了.findIndex()是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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆