For each helper function
Posted: Fri Jul 08, 2016 10:12 pm
If you're like me and hate for loops, this makes iterating a little simpler within Scripter:
Example usage:
Output
Code: Select all
/*
Foreach helper function
callback
Function to execute for each element, taking three arguments:
currentValue
The current element being processed in the array.
index
The index of the current element being processed in the array.
array
The array that forEach() is being applied to.
*/
var forEach = function(array, callback){
var currentValue, index;
for (i = 0; i < array.length; i += 1) {
currentValue = array[i];
index = i;
callback(currentValue, i, array);
}
}
Code: Select all
var toAddresses = s.getPropertyValueList('ToAddresses'); // String list property with multiple lines
forEach(toAddresses, function(address, index){
s.log(2, "address "+index+": "+address);
});