[英]How to add specific key values from one object to another array of objects, for each object
[英]How to connect values in array of objects - a specific key in the object
我有几个对象的数组。 每个对象都有一个带数字的钥匙。
我需要对所有这些数字求和
例如:
Users = [
{name: example, age: 10},
{name: example2, age: 30},
{name: example3, age: 15}
]
那就是我尝试过的:
var sum = 0;
for (let i = 0; i < this.shippingMethod.length; i++) {
var currentValue = this.shippingDetails.shippingQuantity
sum += currentValue;
console.log(sum)
return sum
}
尝试这个:
Users = [ {name: "Max", age: 10}, {name: "Fritz", age: 30}, {name: "Tom", age: 15} ] var sum = 0; Users.forEach(function(user) { sum += user.age; }); console.log(sum)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.