[英]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.