How to check if all values of a javascript object within an array is true within React + Typescript?

Viewed 1443

I currently have a unique multiple choice test where some of the questions have multiple choice that are all correct. I'm currently trying to write something to check if every answer is question within the choice. choices is prop of type Array which holds multiple choice questions. I want to be able to check that isCorrect is true for each object within this.props.choices. Currently the structure looks like this:

"choices": [
        {
          "text": "Text 1",
          "isCorrect": true,

        },

        {
          "text": "Text 2",
          "isCorrect": true,
        }
  ]
1 Answers

you want to use every on array so like this:

choices.every(choice => choice.isCorrect)

this will return true if all values are true

Related