I have this array that contains an object which has 4 elements in it:
Task 3: [
{
"action_3": 1,
"action_4": 1,
"action_5": 0,
"action_6": 0
}
]
I have got to this point by doing this:
this.Task3 = this.actions.map(item => {
return {
action_3: item.action_3,
action_4: item.action_4,
action_5: item.action_5,
action_6: item.action_6
}
})
For the next part I would like to check many 1's exist - the result should be 2.
This is my code so far:
task3Progress() {
for (const key of this.Task3) {
const task3length = Object.keys(key).length
//should print 2 to console
console.log(Object.values(key).reduce(
(count, value) => count + (compare === value ? 1 : 0),
0)
);
//prints 4 to screen
return task3length
}
},
I would like to do 2 things:
1) return a count of 4
for the number of elements that exist
2) do a check for how many 1
's exits, and return a 2
How do I do this?