I got a issue I would like feedback on how it can be solved.
Here's my JSON:
questions: [
{
question: 'lala',
answer: 'papa',
categories: ['Handla']
},
{
question: 'xxxx',
answer: 'yyyy',
categories: ['Reklamation']
},
{
question: 'abcefg',
answer: 'gooooogle',
categories: ['Reklamation']
}
]
I want to iterate over this question array and append the ALL the object.categories to a new array and then filtering out the duplicated ones. So basically my response should be:
["Handla", "Reklamation"]
const categories = data.questions.reduce((prev, curr) => prev.concat(curr.categories), []).filter((category, index, array) => array.indexOf(category) === index).vars cats=[]; for (var i = 0; i < questions.length; i++) { var cat = questions[i].categories[0]; if (cats.indexOf(cat) == -1) cats.push(cat); }- I get tears in my eyes ;)