[Vuejs]-Average Sub-Array Data from JSON

0👍

Try using .reduce() like this:

averageVote(data) {
  let total = data.votes.reduce((accumulator, vote) => {
    return accumulator += vote.vote;
  }, 0);
  let count = data.votes.length;
  return total / count;
}

0👍

Just parse this answer (JSON.parse), iterate over votes, sum vote values and then divide the sum by length of votes table. Simple as that.

Leave a comment