I am saving a record on button click but it always throwing an error.
I am including an if else condition. I have surpassed all the conditions but still my code is going to the if condition but It should not go to if condition.
code is -
my this.state.question.options value is -
[
{
id:3250,
label:'good answer',
assert:1
position:1
},
{
id:3249,
label:'bad answer',
assert:0
position:2
}
]
and I am checking if else condition as -
if (this.state.question.options.filter(o => o.assert === true).length <= 0) {
hasError = true
errorKey = 'add-question-modal-missing-assert-options'
}
else {
alert("test");
}
my code should goto else part and print test as alert but it is going to if part and showing error. Why ?
I wanna show else part i.e test as alert
0and1). There is noassertkey, and definitely not one with a strict value oftrue. Then again, the array is not valid as your string values are not quoted. Please provide an MCVE.truewhen the occurringassertvalues are0and1also seems weird.