Access Array value by dynamic key?

Is it possible to access an array value by a dynamic key?

For instance, if I have an array myArray with [value1, value2, value3] and I want to access value2 I can do that by myArray.items[1] but I can’t figure out how to get a value with a dynamic key.

Thx.

Wappler’s built-in .where() formatter might not work because I assume it would be expecting an array of objects, instead of an array of strings

You might need a custom formatter for this

Finding a certain value inside an array is achieved through the .indexOf method in JavaScript. I doubt this is implemented in Wappler’s back-end, so you would need to create a custom formatter

Thanks! Here’s the formatter if anyone needs it…

dmx.Formatter(‘array’, ‘arrayIndex’, function (val, i) { return val[i]; });

called like so…

yourArray.items.arrayIndex(indexNumber)

dmx.Formatter('array', 'indexOf', function (val, str) { return val.indexOf(str); }

This would return the index of where the string you want is located

Awesome! Thanks for your help!!