当前位置:网站首页>计算数组某个元素的和
计算数组某个元素的和
2022-08-11 10:00:00 【花笙_】
let arr=[
{name:'张三',value:10},
{name:'李四',value:11},
{name:'王五',value:12},
]
let counts = 0
for (let i = 0; i < arr.length; i++) {
if (arr[i].value) {
counts += arr[i].value
}
}
console.log(counts) // 33

或者用下面的代码替换for循环的代码,如图
arr.map(res=>{
return counts +=res.value
})
有别的方法欢迎在评论区补充~
边栏推荐
- How to improve the efficiency of telecommuting during the current epidemic, sharing telecommuting tools
- MySQL表sql语句增删查改_修改_删除
- TIOBE - 2022年8月编程语言排行
- 零基础创作专业wordpress网站12-设置标签栏图标(favicon)
- 【Prometheus】 Grafana数据与可视化
- Software custom development - the advantages of enterprise custom development of app software
- Simple interaction between server and client
- ES6: Expansion of Numerical Values
- Primavera P6 Professional 21.12 Login exception case sharing
- 腾讯电子签开发说明
猜你喜欢
随机推荐
Primavera Unifier -AEM 表单设计器要点
Six functions of enterprise exhibition hall production
A few days ago, Xiaohui went to Guizhou
华为WLAN技术:AC/AP 实验
OAK-FFC系列产品上手指南
php将form表单内容提交到数据库后中文变成??(问号)
[UE] 入坑
The mathematical knowledge required for neural networks, the mathematical foundation of neural networks
大家有遇到这种错吗?flink-sql 写入 clickhouse
Typora和基本的Markdown语法
你觉得程序员是一个需要天赋的职业吗?
idea plugin autofill setter
Primavera Unifier advanced formula usage sharing
MongoDB 非关系型数据库
软件定制开发——企业定制开发app软件的优势
神经痛分类图片大全,神经病理性疼痛分类
使用stream实现两个list集合的合并(对象属性的合并)
Unity shader test execution time
零基础创作专业wordpress网站12-设置标签栏图标(favicon)
SQL语句









