Forum Discussion
tstack
8 years agoFormer Employee
If you’re really concerned about performance, you might want to split the $fields
property in an upstream snap. Otherwise, it will be split for every property in the object when it is done in the filter() callback function, like here:
$.filter((value, key) => ($fields.split(',')).indexOf(key) >= 0)
(Really, the compiler should figure this out optimize away, but that’s not done right now.)
The [*]
syntax is for JSON-Paths and is not usable in the expression language, which is why this won’t work:
$input[*].filter((value, key) => ($fields.split(’,’)).indexOf(key) >= 0)
Instead, you’ll need to use the map() method to transform the elements of the $input
array. So, something like:
$input.map(x => x.filter((value, key) => ($fields.split(’,’)).indexOf(key) >= 0))