I wrote this function to access an array. It modifies the array and returns it.
function init(required array arr) { var arrLen = arrayLen(arr); for (var i = 1; i <= (arrLen / 2); i++) { var swap = arr[arrLen + 1 - i]; arr[arrLen + 1 - i] = arr[i]; arr[i] = swap; } return arr; }
I tested it and it works with arrays of strings, as well as objects, etc.
writeOutput(arrayReverse(['a','b','c']) ); // => ['c', 'b', 'a'] var a = ['apple', 'ball', 'cat', 'dog']; arrayReverse(a); writeOutput(a); // => ['dog', 'cat', 'ball', 'apple']
I put it in my own component, so it is easier to use in different projects.
source share