当前位置:网站首页>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
边栏推荐
- kubectl 获取pod日志 —— 筑梦之路
- LED高精度体重秤方案规格书
- How to encrypt the data in MySQL database? Mysql8.0 comes with new features
- Hacker introductory tutorial (very detailed) from zero basic introduction to proficiency, it is enough to read this one.
- Program design Comprehensive Experiment III
- C background GC cause and effect
- [openbmc series] 4. Start the process and use qume to simulate ast2600 EVB
- 1.2 pedestrian recognition based on incremental generation of occlusion and confrontation suppression (code understanding and experimental progress + Report)
- System information function of MySQL function summary
- [redis] redis penetration, avalanche and breakdown
猜你喜欢

解决 ViewUI 表格无数据时展示滚动条的问题

Online judge output overrun

Understanding of basic concepts of channel capacity and channel bandwidth

长安链数据存储源码分析

PC博物馆(3) MITS Altair 8800

电容串联与并联以及电容串联与平衡电阻

软件配置 | tigerVNC的下载、安装及配置

技术分享 | 接口自动化测试中,如何做断言验证?

C# 后台GC 的前因后果

2022 love analysis · smart community manufacturer panoramic report manufacturer solicitation
随机推荐
pytorch lstm+attention
顶级“黑客”能厉害到什么地步?无信号也能上网,专家:高端操作!
How to quickly improve the three minute response rate of Tiktok store? What will affect the reply rate of Tiktok store?
Assignment 1 - Hello World ! - Simple thread Creation
[redis] several deployment methods of redis
连接池-归还连接详解(上)
C171: attendance system
Capacitance in series and in parallel and capacitance in series and balance resistance
C background GC cause and effect
技术分享 | 接口自动化测试中,如何做断言验证?
C243:考试排名
中国业务型CDP白皮书 | 爱分析报告
Static test. 2021.01 .13
Compiling ncnn with vs
New library online | cnopendata detailed address data of all patents in China
Rodin 安装 SMT Solvers 插件
C # find perfect numbers, output daffodils and use of classes
Function summary
邬贺铨:因地制宜 数字化技术赋能“双碳”实践
uva1377