Looking to find the total count of properties that are true from an array of objects? Here's an example:
let data =
[
{
comment: true,
attachment: true,
actionPlan: true
},
{
whenValue: '',
comment: true,
attachment: false,
actionPlan: true
}
]
An attempt was made with the following code, but it didn't work as expected:
const countObj = questionAttributes.questionMandatoryOptions.reduce((acc, curr) => {
return {
// intend to extract properties with true values
};
});
If you want to achieve this for a single item in the array, you can use the following snippet:
const total =
options[0];
const totalelections = Object.values(
total
).filter((v) => v).length;