Array map formatter

Hi @patrick,

I’ve seen array mapping is implemented as an array formatter, but It doesn’t appear in the UI to me.
Is it functional even if only in code? If so what arguments is it expecting?

Yes, the map and filter formatter is in there for a very long time. We never implemented these because it was not possible to have sub expressions using the UI. The argument is a string with an expression.

Usage is like:

['a','b','c'].map('$value.uppercase()')
// returns ['A','B','C']
['a','b','c'].map('{ index: $index, value: $value }')
// returns [{ index: 0, value: 'a'},{ index: 1, value: 'b'},{ index: 2, value: 'c'}]
['api','access','basis','clear'].filter('$value.startsWith("a")')
// returns ['api','access']
3 Likes

Thanks once again. I can now ditch some custom formatters I had.

In case it’s helpful to people reading this thread, @patrick gave a practical example of using the map formatter here. I think it can be a very useful feature.

1 Like