How to check if value exists in Array object

Hi,
To check whether the value (for example X0000002) exists in the array or not, I use the for loop, then it can be determined.
find-value-inside-array

[{"id":"313fcd3d.d1cfa2","type":"inject","z":"fa444759.e27348","name":"","topic":"","payload":"","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":1130,"y":500,"wires":[["c05793c0.58d6a"]]},{"id":"c05793c0.58d6a","type":"function","z":"fa444759.e27348","name":"","func":"\nvar arrData = [];\narrData.push({index: \"X0000001\"});\narrData.push({index: \"X0000002\"});\narrData.push({index: \"X0000003\"});\narrData.push({index: \"X0000004\"});\nmsg.arrData = arrData;\n\nreturn msg;","outputs":1,"noerr":0,"x":1270,"y":500,"wires":[["80501ae2.f02918"]]},{"id":"80501ae2.f02918","type":"debug","z":"fa444759.e27348","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":1410,"y":500,"wires":[]}]

But is there a more concise way like contains or includes to check?
Thanks in advance!

Search for JavaScript array includes.

1 Like

I have tried the following already solved it.

var exists = arrData.some(c => c.index === "X0000002");
2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.