I
I
ignis212021-06-28 11:36:31
JavaScript
ignis21, 2021-06-28 11:36:31

How to add and find the average value of an object?

There are 4 objects, how can I calculate the average age in them?
1) friend1 {
name: Ihor
age: 22
}
2) friend2 {
name: Vlad
age:25
}
3) friend3 {
name: Oleh
age: 28
}
4) friend4 {
name: Sasha
age:20
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
0
0xD34F, 2021-06-28
@ignis21

Put the objects into an array, and

arr.reduce((acc, n) => acc + n.age, 0) / arr.length

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question