Chartjs-How to reorganize data to display how many times a string appears in an array object?

0👍

First you filter it by each category, then make an array of language Strings. Then make object that holds each language appearance by counting it.

const categroy1data = data.filter(val => val.category === 1).map(val => val.language);
// => ['Danish', 'Dutch', 'Spanish' ... ]

const category1result = {}
category1data.forEach(val => {
  category1result[val] = 1 + (category1result[val] || 0)
})
// { 
//   Danish: 3,
//   Dutch: 2,
//   Spanih: 1,
// }

Leave a comment