I want to output the number of all questions for each post in ReactJs. For this i created the next code:
const posts = [{
title: 1,
id: "123"
},
{
title: 2,
id: "1234"
},
{
title: 3,
id: "12345"
}
]
const questions = [{
id: 55,
name: 'question one',
id_post: 123
},
{
id: 56,
name: 'question two',
id_post: 123
},
{
id: 57,
name: 'question three',
id_post: 1234
},
{
id: 58,
name: 'question four',
id_post: 123
},
];
posts.map(({id}) => {
let count = 0
console.log(questions.filter(({id_post}) => (id_post == id)).length)
})