当前位置:网站首页>Calculate the sum of an element of an array
Calculate the sum of an element of an array
2022-08-11 10:03:00 【Huasheng_】
let arr=[{name:'Zhang San',value:10},{name:'Li Si',value:11},{name:'Wang Wu',value:12},]let counts = 0for (let i = 0; i < arr.length; i++) {if (arr[i].value) {counts += arr[i].value}}console.log(counts) // 33
Or replace the code of the for loop with the following code,As shown
arr.map(res=>{return counts +=res.value})
There are other methods, welcome to add in the comment area~
边栏推荐
猜你喜欢
wordpress插件开发03-简单的all in one seo 插件开发
同态加密简介HE
Primavera Unifier - AEM Form Designer Essentials
MySQL select count(*) count is very slow, is there any optimization solution?
Typora and basic Markdown syntax
HDRP Custom Pass Shader Get world coordinates and near clipping plane coordinates
Data middle platform program analysis and development direction
SAP 产品增强技术回顾
网络模型(DeepLab, DeepLabv3)
php将form表单内容提交到数据库后中文变成??(问号)
随机推荐
MySQL约束
Typora and basic Markdown syntax
How to improve the efficiency of telecommuting during the current epidemic, sharing telecommuting tools
Oracle database use problems
【UOJ 454】打雪仗(通信题)(分块)
分割学习(loss and Evaluation)
HDRP shader 获取像素深度值和法线信息
爆料!前华为微服务专家纯手打500页落地架构实战笔记,已开源
Primavera Unifier - AEM Form Designer Essentials
go基础之并发
canvas图片操作
Open Office XML 格式中的 Style 设计原理
【Prometheus】 Grafana数据与可视化
腾讯电子签开发说明
HDRP shader 获取阴影(Custom Pass)
华为WLAN技术:AC/AP 实验
MySQL表sql语句增删查改_修改_删除
数据库的索引和其底层数据结构
【无标题】超时超时超时超时超时
How to determine the neural network parameters, the number of neural network parameters calculation