当前位置:网站首页>计算数组某个元素的和
计算数组某个元素的和
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
})
有别的方法欢迎在评论区补充~
边栏推荐
- Adobe LiveCycle Designer 报表设计器
- HDRP Custom Pass Shader 获取世界坐标和近裁剪平面坐标
- database transaction
- MySQL数据库基础_常用数据类型_表设计
- PowerMock for Systematic Explanation of Unit Testing
- NT 内核函数原型大全
- Have you encountered this kind of error? flink-sql writes to clickhouse
- dreamweaver网页设计作业制作 学生个人网页猫眼电影 WEB静态网页作业模板 大学生个人主页博客网页代码 dw个人网页作
- 网络流行简笔画图片大全,关于网络的简笔画图片
- 前几天,小灰去贵州了
猜你喜欢

深度学习100例 —— 卷积神经网络(CNN)识别眼睛状态

Primavera Unifier advanced formula usage sharing

假设检验:正态性检验的那些bug——为什么对同一数据,normaltest和ktest会得到完全相反的结果?

WooCommerce电子商务WordPress插件-赚美国人的钱

训练一个神经网络要多久,神经网络训练时间过长

力扣题解8/10

STM32入门开发 LWIP网络协议栈移植(网卡采用DM9000)

同态加密简介HE

数字钱包红海角逐,小程序生态快速引入可助力占领智慧设备入口

Validate the execution flow of the interceptor
随机推荐
【luogu CF1286E】Fedya the Potter Strikes Back(字符串)(KMP)(势能分析)(线段树)
HDRP Custom Pass Shader Get world coordinates and near clipping plane coordinates
Oacle数据库使用问题
Validate the execution flow of the interceptor
自定义卷积核的分组转置卷积如何实现?
HDRP shader to get shadows (Custom Pass)
单元测试系统化讲解之PowerMock
Convolutional Neural Network Gradient Vanishing, The Concept of Gradient in Neural Networks
halcon实例
【每日一题】640. 求解方程
Primavera Unifier -AEM 表单设计器要点
MongoDB 非关系型数据库
The mathematical knowledge required for neural networks, the mathematical foundation of neural networks
QTableWidget 使用方法
最强大脑(9)
收集awr
软件定制开发——企业定制开发app软件的优势
Simple interaction between server and client
Six functions of enterprise exhibition hall production
数据库 SQL 优化大总结之:百万级数据库优化方案