当前位置:网站首页>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;
})
边栏推荐
猜你喜欢
随机推荐
Qt Creator + CMake 运行调试总会自动 build 所有目标
面试官:生成订单30分钟未支付,则自动取消,该怎么实现?
目标检测学习笔记
The interviewer asked me how to divide the database and the table?Fortunately, I summed up a set of eight-part essays
踏上编程之路,你必须要干的几件事
pytorch中的一维、二维、三维卷积操作
Redis first meeting
关于LocalDateTime的全局返回时间带“T“的时间格式处理
Temporal对比Cadence
基于flask的三方登陆的流程
三子棋讲解(C语言)
Interviewer, don't ask me to shake hands three times and wave four times again
wpf ScrowViewer水平滚动
pycharm专业版使用
torch.normal function usage
有了MVC,为什么还要DDD?
Three handshakes and four waves
剑指offer基础版 ---- 第27天
可以“繁殖”的程序
剑指offer专项突击版 ---第 5 天