filter和find的区别

简介: filter和find的区别

filter和find的区别


filter返回值为原数组中所有符合条件的集合,为一个新数组。

find返回值为在原数组中查找到的第一项符合条件的元素,返回当前项。

使用场景:

filter一般为需要过滤其他项的时候使用。

find则更为精准,拥有指定性,更适合使用来通过id等唯一凭证来查找指定的项。

两者类似于class和id。

arr.find(item=>{})
arr.filter(item=>{})

相关文章
|
5月前
|
JavaScript 前端开发
filter() 方法使用
filter() 方法使用
17 0
|
11月前
|
JavaScript 索引
vue 数组处理= 循环--查找过滤--添加删除--去重[.every()/.some()/.find()/.filter()/.forEach()/.map()]
vue 数组处理= 循环--查找过滤--添加删除--去重[.every()/.some()/.find()/.filter()/.forEach()/.map()]
191 0
vue 数组处理= 循环--查找过滤--添加删除--去重[.every()/.some()/.find()/.filter()/.forEach()/.map()]
常见遍历方法 for循环、forEach、map、filter、find、findIndex、some、every
常见遍历方法 for循环、forEach、map、filter、find、findIndex、some、every
136 0
|
算法 容器
常用查找算法 find() find_if() adjacent_find() binary_search() count() count_if()
常用查找算法 find() find_if() adjacent_find() binary_search() count() count_if()
|
Serverless 索引 Python
内置函数 -- filter 和 map
Construct an iterator from those elements of iterable for which function returns true. iterable may be either a sequence, a container which supports iteration, or an iterator. If function is None, the identity function is assumed, that is, all elements of iterable that are false are removed.
106 0
|
安全 Shell