cancel
Showing results forย 
Search instead forย 
Did you mean:ย 

Using 'in' clause in a mapper

krupalibshah
Contributor

I am trying to use โ€˜inโ€™ clause in a mapper snap. But it does not evaluate correctly.

30 in [30,40,50] ----> false

30 in [โ€˜30โ€™,โ€˜4โ€™,โ€˜50โ€™] ----> false

(x => x in [โ€˜4โ€™,โ€˜5โ€™,โ€˜6โ€™])(4) ----> false

Has anyone tried it already? Am I missing anything?

1 ACCEPTED SOLUTION

roi6rieK
New Contributor

Syntax for checking if a value is in an array is the same as in javascript.

Try:

[30,40,50].indexOf(30) != -1 โ€”> true

[30,40,50].indexOf(90) != -1 โ€”> false

The reason for the โ€œ!= -1โ€ is that indexOf returns -1 if the element is not found in an array. Otherwise it returns the index.

Same method works for strings.

View solution in original post

5 REPLIES 5

Thanks, got it working ๐Ÿ™‚