How can I calculate the average of numbers in an array that is in an array?
See the image how I get the data in;
const reviews = [
0: ["5", "1"]
1: ["4"]
2: ["1", "4", "1"]
3: ["1", "4"]
4: ["5", "4"]
5: []
etc etc
]
I would like to know the average of each array so:
0: 3
1: 4
2: 2
etc etc
I work in React. I get the data from a selector in React-Redux. I use this for calculating the average review for each user.
code:
const reviews = users
? users.map((review) => {
return review
? review.reviews.map((reviewen) => {
return <p>{reviewen.review}</p>;
})
: "loading ";
})
: "Loading";
console.log(reviews);