I would like to update the stautent status in array list. I would like update status with loop thought the arraylist.
How can I update the status in array list? Now I update all value when the 1st value is updated.
Now I have a list
[
{
"studentId": 3,
"result": 100,
"resultStatus": false,
},
{
"studentId": 2,
"result": 20,
"resultStatus": false,
},
{
"studentId": 2,
"result": 51,
"resultStatus": false,
}
]
const checkstatus = (result, passScore) => {
if(result >= passScore){
return true; //pass
} else{
return false; //fail
}
}
this.list = this.list.map(x => ({
...x,
resultStatus: checkstatus(x.result, 50 )
}))
Expect result is
[
{
"studentId": 3,
"result": 100,
"resultStatus": true,
},
{
"studentId": 2,
"result": 20,
"resultStatus": false,
},
{
"studentId": 2,
"result": 51,
"resultStatus": true,
}
]
2
Answers
You can try the following way:
I think you doesn’t need any function to calculate result status