I’ve an asp.net core with react project, I have this code here inside my react component:
const staticTxt = stattxt.filter(x => x.id === userIdD && x.taskId === item.id)[0];
I did a console log for each variable in this line and I get this for stattxt:
[
{
"id": 1002,
"taskId": 3,
"value": "some content"
},
{
"id": 1002,
"taskId": 5,
"value": "some content"
}
]
and this for useridD and item.id:
userIdD: 1002
item.id: 5
why does staticTxt keeps returning undefined? I’ve also tried .find but it returns the same result.
2
Answers
userIdD was a string, therefore returning an undefined
Try == instead of ===. === is unnecessary in most cases.