Forum Discussion

acesario's avatar
acesario
Contributor II
5 years ago

Does snaplogic have a mechanism like includes method? array.includes("value")?

Does snaplogic have a mechanism like includes method?

e.g.
“AwardStatus”:[“ACCEPTED”,“OFFERED”,“CANCELED”],

Something like
$AwardStatus.includes(“CANCELED”) ?

2 Replies

  • Harsha3's avatar
    Harsha3
    New Contributor III

    Hi Acesario,

    We don’t have direct method like .contains() like in the case of string . However we can use the indexOf functionality to find whether the particular element is present in an array or not .

    $AwardStatus.indexOf(“CANCELED”)==-1?“Absent”:“Present”

    Where -1 here means the given element is not present in an array else it will be present . Hope this clarifies the answer .

    Also please refer the below documentation to explore more about array manipulation techiniques.

    https://docs-snaplogic.atlassian.net/wiki/spaces/SD/pages/1438091/Array+Functions+and+Properties

  • bojanvelevski's avatar
    bojanvelevski
    Valued Contributor

    Hello @acesario ,

    You can also use the following expression => .filter(x=>x == “CANCELED”).length != 0
    If the AwardStatus contains “CANCELED” the expression will produce “true”, if not, it will produce “false”.

    Best regards,

    Bojan Velevski