当前位置:网站首页>JS array method foreach and map comparison
JS array method foreach and map comparison
2022-07-27 20:10:00 【qwe122343】
Looked up some JS Array methods forEach and map Information , It is simply sorted out for your reference
map Method
const arrMap = [1, 2, 3, 4, 5];
const arrMapModified = arrMap.map(num => num * 2);
console.log(arrMap);
// [1, 2, 3, 4, 5]
console.log(arrMapModified);
// [2, 4, 6, 8, 10]
map Method raw array arrMap Will not change , Allocate storage space and return a new array arrMapModified
forEach Method
const arrayForEach = [1, 2, 3, 4, 5];
const arrayForEachModified = arrayForEach.forEach((item, index) => arrayForEach[index] = item * 2);
console.log(arrayForEach);
// [2, 4, 6, 8, 10]
console.log(arrayForEachModified);
// undefined
forEach Method raw array arrayForEach Will change , Do not return a new array , The value is undefined
边栏推荐
- Ms721 load test
- Static test. 2021.01 .13
- Detailed introduction to common coordinate system of cesium
- Dcm11- write the function and configuration of the data service ($2e) according to the identifier [based on DaVinci configurator classic]
- Unified Modeling Language (UML) specification
- [Redis] Redis穿透、雪崩和击穿
- ECU software and hardware architecture
- [Redis] Redis几种部署方式
- [redis] several deployment methods of redis
- VALN 11.9
猜你喜欢

十年测试老鸟聊聊移动端兼容性测试

第3章 基本操作

Capacitance in series and in parallel and capacitance in series and balance resistance

Introduction to basic cesium controls

【OpenBMC 系列】4.启动流程 使用qume模拟ast2600-evb

Online judge output overrun

顶级“黑客”能厉害到什么地步?无信号也能上网,专家:高端操作!

C# 后台GC 的前因后果

Chemical giant BASF & Pasqual: using quantum neural network to optimize weather forecast

PMP每日一练 | 考试不迷路-7.27(包含敏捷+多选)
随机推荐
C background GC cause and effect
Introduction to reinforcement learning
Common errors reported by pytorch
Global function
GLTF模型添加关节控制
UnicodeDecodeError: ‘utf-8‘ codec can‘t decode byte 0xff in position 0: invalid start byte
内置函数锁相关
AcWing 692. G巴士计数 差分+前缀和
Introduction to basic cesium controls
使用cpolar建立一个商业网站(5)
C171: attendance system
System information function of MySQL function summary
Qtexttospeech class of QT realizes voice broadcast function
C#网络应用编程,实验2:IP地址转换和域名解析练习
2022年,软件测试还能学吗?别学了,软件测试岗位饱和了...
Sword finger offer 25. merge two sorted linked lists
‘vite‘ 不是内部或外部命令,也不是可运行的程序 或批处理文件
Common operators 9.21
中国业务型CDP白皮书 | 爱分析报告
西数移动硬盘无法读取(高枕无忧的成语)