skip to Main Content

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


  1. Chosen as BEST ANSWER

    userIdD was a string, therefore returning an undefined


  2. Try == instead of ===. === is unnecessary in most cases.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search