I'm trying to check if an array within an object contains an element userAnswer or not. Is there a good way to do this using es6. I've tried a few however, I can't seem to get it to work properly. Most of my attempts return an error. Any help would be appreciated.
Last Attempt
conductedExam.questions.some(question => question.userAnswer.includes(Object))
Data
{
_id: '1',
questions: [
{ name: '1', userAnswer: 'one' },
{ name: '2', userAnswer: 'two' },
{ name: '2' }
]
};
Objectthat you're passing to the.includes? Is that an actual object, or a string like'one', or what? Not entirely sure what the logic you're looking for isObjectmeant to check if any object exists. Is that possible or am I not looking at this correctly.userAnswers in the given input, would you want the output to befalsehere? (you only have strings)