I have found and tried out .includes
to help with this problem. But .includes
did not work as I intended. It actually did find which value in the array match the value in the other array, but it only matched similar values:
result_postid results mapped with commas:
[10,22,12,36,45,206]
item.id results mapped with commas:
[5,13,28,136,400,538]
I tried to figure out why some of the values kept returning true
when they should be clearly false
. Then I came to the conclusion that .includes
was actually taking 36
from result_postid
and matching it with 136
in item.id
. This is how I setup the if statement with .includes
:
{result_postid.includes(item.id) ?
<Text>True</Text>
:
<Text>False</Text>
}
This is the result:
result_postid | item.id | Result
10 != 5,13,28,136,400,538: False
22 != 5,13,28,136,400,538: False
12 != 5,13,28,136,400,538: False
36 = 5,13,28,136,400,538: True <--- this should be false
45 != 5,13,28,136,400,538: False
206 != 5,13,28,136,400,538: False
Is it possible to find if one of the values in the array exactly matches one of values in the other array?
Aucun commentaire:
Enregistrer un commentaire