当前位置:网站首页>find、filter、map的区别
find、filter、map的区别
2022-07-31 05:10:00 【F班的小夏同学】
find
find查询数组中符合条件的第一个元素,如果没有则返回空数组。
var arr=[1,2,3,4,5,6,7]
var newArr=arr.find(v=>v===4)
var men=[
{
name:'zhangsan',age:'18',sex:'女'},
{
name:'lisi',age:'10086',sex:'nan'},
{
name:'xiaohuangren',age:'23',sex:'nan'},
{
name:'xiaokeai',age:'18',sex:'女'},
]
var women= men.find(person=> person.sex==='女')
filter
过滤数组元素,返回过滤后的数组,若没有符合条件的元素,则返回空数组。
//输出大于5的数,组成新数组
var arr = [1,2,3,4,5,6,7];
var newarr = arr.filter(function(num){
reture num>5?num:''
});
map
对每个数组元素进行相同的操作,返回一个与原数组length相等的数组
//给数组的每一个元素加1,组成新数组
var arr = [1,2,3,4,5,6,7];
var newarr=arr.map(function (num) {
return num+1;
})
边栏推荐
猜你喜欢
随机推荐
MySQL(更新中)
tf.keras.utils.get_file()
【mysql 提高查询效率】Mysql 数据库查询好慢问题解决
MySQL (updating)
The interviewer asked me how to divide the database and the table?Fortunately, I summed up a set of eight-part essays
面试官竟然问我怎么分库分表?幸亏我总结了一套八股文
踏上编程之路,你必须要干的几件事
The TOKEN value of Kubernetes joining the cluster expires
账号或密码多次输入错误,进行账号封禁
关于superset集成到自己的项目中
剑指offer专项突击版 ---- 第 6 天
精解四大集合框架:List 核心知识总结
Mysql——字符串函数
【数据库学习】Redis 解析器&&单线程&&模型
有了MVC,为什么还要DDD?
Object Detection Study Notes
详解扫雷游戏(C语言)
Interview Redis High Reliability | Master-Slave Mode, Sentinel Mode, Cluster Cluster Mode
Workflow番外篇
数据库上机实验3 连接查询和分组查询