当前位置:网站首页>(JS)数组中纯函数
(JS)数组中纯函数
2022-06-29 09:57:00 【不愿透露姓名的余菜鸟】
- 不改变源数组(没有副作用)
- 返回一个数组
- Arrat.concat(value)
合并数组并返回一个新数组,不对原数组做改变(与push相似,在数组末尾添加value)
let array = [1,2,3,4,5];
let x = array.concat([10,20])
console.log(x) // [1,2,3,4,5,10,20]
- Array.map(function)
遍历数组,如果return出数组值,将成为一个新数组,如果使用判断,则不符合条件的返回false
let array = [1,2,3,4,5];
let x = array.map(result=>{
return result*10;
});
console.log(x) //[10, 20, 30, 40, 50]
- Array.filter(function)
过滤数组,返回符合条件的值
let array = [1,2,3,4,5];
let x = array.filter(num=>{
return num>2
})
console.log(x)//[3, 4, 5]
- Array.slice(start ,end)
拷贝数组从start到end(不包括end)的值,返回一个新数组,不会对源数组进行改变
let array = [1,2,3,4,5];
let x = array.slice(2,3)
console.log(array) //[1,2,3,4,5]
console.log(x) //[3]
边栏推荐
- 智能组卷系统设计
- SQL Server 数据库增删改查语句
- Recommended embedded learning books [easy to understand]
- CS231n-2022 Module1: 神经网络要点概述(2)
- Print leap years between 1000 and 2000 (C language)
- ZABBIX monitors various MySQL indicators
- 高薪程序员&面试题精讲系列117之怎么保证Redis缓存与数据库的数据一致性?
- [FreeRTOS] 08 mutex semaphores and priority inversion
- BUUCTF RE-easyre
- The use and difference of watch listening and computed calculation attributes
猜你喜欢

Essential for efficient work: how can testers improve their communication skills?

Hystrix fuse: Service fusing and service degradation

基于STM32+RFID设计的宿舍检修管理系统

Print prime numbers between 100 and 200 (C language)

8年打磨,《游戏设计梦工厂》发布史诗级更新!

# 【OpenCV 例程200篇】214. 绘制椭圆的参数详解

arcgis创建postgre企业级数据库

Offensive and defensive world re insfsay

每日刷题记录 (七)

Attribute in C
随机推荐
UserWarning: Usage of dash-separated ‘script-dir‘ will not be supported in future versions. 笔记
Linux下Redis安装及集群搭建
Here comes the tutorial of datawhale recommendation system!
The use and difference of watch listening and computed calculation attributes
你的项目需要自动化测试吗?
Dormitory maintenance management system based on stm32+rfid design
Buuctf-- connotative software
【Rust每周一库】Tokei - 统计代码行数等信息的实用工具
高效工作必备:测试人如何提高沟通技能?
各位大佬 请教下mysqlcdc的数据不支持开窗函数吗 像row_number ,lead这种
30-year-old female, ordinary software testing Yuanyuan, confused and anxious about her career
30岁,女,普通软件测试媛,对职业的迷茫和焦虑
Attribute in C
【C语言进阶】文件操作(二)
[FreeRTOS] 08 mutex semaphores and priority inversion
【C语言进阶】通讯录实现
【C语言进阶】动态内存管理
有人遇到FlinkCdc同步MySQL时候出现的这个问题吗?
工具箱之 IKVM.NET 项目新进展
全面理解Volatile关键字