How to use map() to filter for a label that starts with a value, rather than is equal?

map() allows us to grab all values of a complex array that have a key with a value that we specify it’s equal to - but how about if we want to say it starts with something, rather than is exactly equal?

For example, say we have:

[ { myKey: abc123 }, { myKey: abc123456 }, { myKey: xyz } ]

map(arr, myKey, abc123) can return the first object with success

But say I want to return the first two objects, both of which start with ‘abc123’ - but the second one continues with a different value?

map(arr, myKey, startsWith(abc123)) for example

Is there a way to achieve this? In traditional programming languages, you’re usually able to throw in an actual conditional to return an object that meets any criteria you specify - not just being limited to equal or not equal to a string.

Hi @TJ,

As you have stated you won’t be able to achieve this by simply using map function.

Only other way that you can do in Make is to use Iterator and Array Aggregrator, and add a filter in-between that will do the startsWith comparison.

There are other approaches for this, First one is Custom Function which I believe is only available for enterprise plan, other will be to use Custom App and write IML function.

1 Like

Hi @TJ :wave:

just wanted to step in and ask whether you tried @Runcorn’s solution. If yes did it do the magic for your problem?

Thank you for sharing with us your progress. :rose:

Honestly, can’t remember what in particular I was trying to use this for. But I think I ended up doing something @Runcorn 's solution. Thank you both!