Forum Discussion
The filter() function is taking (a, b, c) as parameters and everything after => is an “on the fly” function to help determine which values from (a, b, c) should be in the output. If I’m not mistaken, the function is searching string ‘c’ to see if it contains string ‘a’, and if it so, does that equal integer ‘b’. Basically, if string ‘a’ is detected inside string ‘c’ at the expected location ‘b’, then the document would pass through the filter, otherwise it would be excluded.
In SnapLogic you can use filter() on Objects and Arrays. If you’re able to share more context around the expression such as sample data, or all/part of a pipeline that uses it, we can try to get you more information.
Please let us know if that helps and if some part still needs clarified, please let us know.
- Anjali5 years agoNew Contributor
To remove duplicate entries in an array:
Expression :
$myarray.filter((item, pos, a) => a.indexOf(item) == pos)
where $myarray is a normal array containing [“Fred”, “Wilma”, “Fred”, “Betty”, “Fred”, “Barney”]
Result : A new array containing [Fred, Wilma, Betty, Barney].
I found this example in documentation. but not able to understand how this function is deleting duplicates. Can you explain with this example