Home > front end >  How to remove the object inside the numerical come
How to remove the object inside the numerical come

Time:09-17

Bosses, beginner JS a lot of places do not understand, how to remove this object inside numerical score, and then take the average, thank you

CodePudding user response:

Var Bobby=[
{Itme: "aaaa", Score: 56},
{Itme: "BBBB", Score: 94},
{Itme: "CCCC", Score: 87}
];
Var sum=Bobby. Reduce ((s, v)=& gt; S + v. core, 0);
Alert (sum/Bobby. Length);

CodePudding user response:

First, you use of array for... Of and entries () method is not very appropriate entries () method is generally used for object for the key and the value of the array key is the subscript
The implementation of the way) you want such a
 
Const arr=[
{Item: "English", Score: 70},
{Item: "Math", Score: 92},
{Item: "Chinese", Score: 85},
]

Let count=0;
for(var i=0; I & lt; Arr. Length; I++) {
The count +=arr [I] Score
}
The console. The log (count);

CodePudding user response:

//this is an array, you have to traverse the
Bobby. Foreach (function (v) {
The console. The log (v.I tem, v. core)
})
  • Related