score:2

Accepted answer
const data = [{
  "1": { drama: { Comedy: true, Romance: true, BuddyComedy: false } },
  "2": {
    drama2: { Tragedy: true},
    others: "Dystopian",
  },
  id: "zaMR9TR7hNV3p3VFNumyNbXMto93",
  genre: {
    selected: "Movie",
  },
  displayName: "p1"
}, 
 {
  "1": { drama: { Tragedy: true } },
  "2": {
    drama2: { Romance: true}
  },
  id: "zaMR9TR7hNV3p3VFNumyNbXMto93", //sample id
  genre: {
    selected: "Movie",
  },
  displayName: "p2"
}]

const movies = data.filter(v => v.genre?.selected == "Movie");
const counts = movies.reduce((acc, cur) => {
    return Object.entries(cur["1"].drama).reduce((acc, [key,value]) => { 
        if (value) { 
            acc[key] = (acc[key] || 0) + 1;
        }
        return acc;
    }, acc)
}, {})

console.log('Counts:', counts)

Related Query

More Query from same tag