当前位置:网站首页>计算数组某个元素的和
计算数组某个元素的和
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
})
有别的方法欢迎在评论区补充~
边栏推荐
- 【Prometheus】 Grafana数据与可视化
- 最强大脑(9)
- 力扣打卡----打家劫舍
- 【无标题】(完美解决)uni-app 小程序下拉刷新后刷新图标无法正常恢复的问题
- 关于ts中的指针问题call,bind, apply
- Primavera P6 Professional 21.12 Login exception case sharing
- 2022-08-10:为了给刷题的同学一些奖励,力扣团队引入了一个弹簧游戏机, 游戏机由 N 个特殊弹簧排成一排,编号为 0 到 N-1, 初始有一个小球在编号
- STM32入门开发 LWIP网络协议栈移植(网卡采用DM9000)
- 利用mindspore下面mindzoo里面的yolov3-darknet53进行目标识别,模型训练不收敛
- 网络流行简笔画图片大全,关于网络的简笔画图片
猜你喜欢
Deploying Robot Vision Models Using Raspberry Pi and OAK Camera
Primavera Unifier 高级公式使用分享
【Prometheus】 Grafana数据与可视化
How to use QTableWidget
Huawei WLAN Technology: AC/AP Experiment
wordpress插件开发03-简单的all in one seo 插件开发
WooCommerce电子商务WordPress插件-赚美国人的钱
How to determine the neural network parameters, the number of neural network parameters calculation
Typora and basic Markdown syntax
困扰所有SAP顾问多年的问题终于解决了
随机推荐
WooCommerce Ecommerce WordPress Plugin - Make American Money
如何开手续费低靠谱正规的期货账户呢?
【luogu CF1286E】Fedya the Potter Strikes Back(字符串)(KMP)(势能分析)(线段树)
HDRP Custom Pass Shader 获取世界坐标和近裁剪平面坐标
WooCommerce电子商务WordPress插件-赚美国人的钱
VideoScribe卡死解决方案
Three handshakes and four waves
HDRP shader gets pixel depth value and normal information
Convolutional Neural Network System,Convolutional Neural Network Graduation Thesis
What is the difference between the qspi interface and the ordinary four-wire SPI interface?
A few days ago, Xiaohui went to Guizhou
【Prometheus】Alertmanager告警全方位讲解
Data middle platform program analysis and development direction
深度学习100例 —— 卷积神经网络(CNN)识别验证码
期货开户最低的是交易所手续费不加佣金
VC6.0 +WDK 开发驱动的环境配置
Primavera Unifier -AEM 表单设计器要点
qspi 接口与普通四线SPI 接口什么区别?
保证金监控中心保证期货开户和交易记录
MySQL表sql语句增删查改_修改_删除