Array Functions
Below is the list of functions on arrays that we officially support and where we follow the official documentation. Please note that we may support more functions but we only list the ones where we have completed testing. For details on the functions please refer to Mozilla documentation.
The difference between direct and chained support related to the support for making chained calls – e.g first a filter and then a map function, in most places we will support both, but there may be situations where only one of the two is supported.
Name | Supported directly | Supported chained | Comment | Example |
---|---|---|---|---|
every |
var allPurchaseAbout100 = recipient.table.PURCHASE.every(function(line) {return line.PRICE>100});
|
|||
filter |
var discountPurchases = recipient.table.PURCHASE.filter(function(line) {return line.DISCOUNT});
|
|||
find |
var firstDiscountProduct = recipient.table.PURCHASE.find(function(line) {return line.DISCOUNT});
|
|||
findIndex |
var indexOfFirstOver400 = recipient.table.PURCHASE.findIndex(function(line) {return line.PRICE>400});
|
|||
flatMAp |
var priceAndDiscount = recipient.table.PURCHASE.flatMap(function(line) { return [line.PRICE,line.DISCOUNT]; });
|
|||
forEach |
recipient.table.PURCHASE.forEach(function(line) {logger.info(line.PRICE);});
|
|||
join | We don’t have a standard way of printing a row, so you need to map it yourself first before you join |
var stringVersion = recipient.table.PURCHASE.map(function(l) {return l.PRICE}).join();
|
||
map |
var prices = recipient.table.PURCHASE.map(function(l) {return l.PRICE});
|
|||
pop | When you call pop directly on the table the record is deleted from the table. If you call pop after any transformation of the records even if it’s simply a filter or a reverse then the item is only removed from the array but not deleted |
var removedItem = recipient.table.PURCHASE.pop();
|
||
push | Documented elsewhere. Please note that if you have applied any function to the original table before calling push the call will fail. |
var allPurchaseAbout100 = recipient.table.PURCHASE.every(function(line) {return line.PRICE>100});
|
||
reduce |
ar sum = recipient.table.PURCHASE.reduce(function(total,line) {return total + line.PRICE},0):
|
|||
reduceRight | This is reduce right which is basically the same as reverse + reduce, not fold right which you may know from functional programming. More details after the table for those interested |
var sum = recipient.table.PURCHASE.reduceRight(function(total,line) {return total + line.PRICE},0):
|
||
reverse | Due to the requirement that reverse updates the original array as well as returning a new we cannot support this on our table models, also please remember that Agillic makes no guarantee on the order of the rows of any table. |
var reversed = recipient.table.PURCHASE.map(function(l) {return l.PRICE}).reverse();
|
||
shift | When you call shift directly on the table the record is deleted from the table. If you call shift after any transformation of the records even if it’s simply a filter or a reverse then the item is only removed from the array but not deleted |
var removedItem = recipient.table.PURCHASE.shift();
|
||
slice | Remember that slice produces a copy of the array so calling slice on the table will leave the table itself untouched i.e it will not delete any records not part of the result of slice |
var sliced = recipient.table.PURCHASE.slice(1,3);
|
||
some |
var hasMadePurchaseOver100 = recipient.table.PURCHASE.some(function(line) {return line.PRUICE>100});
|
|||
sort | Calling sort on the table directly will not sort the actual records in the table but only return a copy, calling sort on the output of any function will also sort the original input. E.g var sorted = recipient.table.LINES.sort(function(i1,i2) {return ...}); logger.info(sorted[0]+" "+recipient.table.LINES[0]) may log two different values. Due to our implementation of sort you will not have access to the index nor the original array in your function. |
var sorted = recipient.table.PURCHASE.sort(function(i1,i2) { return i1.PRICE - i2.PRICE; });
|