I keep on finding that Array functions are missing in GAS, eg calling find
gives the error: Cannot find function find in object
The only docs I can find on this are somewhat ambiguous: https://developers.google.com/apps-script/guides/services/#basic_javascript_features
Apps Script is based on JavaScript 1.6, plus a few features from 1.7 and 1.8. Many basic JavaScript features are thus available in addition to the built-in and advanced Google services: you can use common objects like Array, Date, RegExp, and so forth, as well as the Math and Object global objects. However, because Apps Script code runs on Google's servers (not client-side, except for HTML-service pages), browser-based features like DOM manipulation or the Window API are not available.
How can I see what exact methods are available on Array?
When in Doubt, Test Yourself!
Check it out for yourself with:
Note: this function list is not exhaustive and is only for example purposes.
Which outputs something like:
Alternatively, robd's method works fine too, except it only tells you the list of methods that are visible. It doesn't tell you:
So I prefer my slightly more explicit approach.
An even better method than mine would be to actually check function test cases to make sure behaviors are correct, but... oh well...
GAS Function Call Support Fun Fact
Here's something weird: I first tested using an implementation with
.apply()
instead of.call()
(out of habit), and strangely enough only the methods supported in the GAS editor appeared as supported. Works fine using.call()
though. Rather odd.I Want my Functional Tools Back!
Check out underscoreGS.
Besides robd's answer there is also the 2d arrays library.
According to the picture (but not the documentation) that one has a find function
Logger.log(Object.getOwnPropertyNames(Array.prototype))
gives the following, which I think it is the correct list:[constructor, toString, toLocaleString, toSource, join, reverse, sort, push, pop, shift, unshift, splice, concat, slice, indexOf, lastIndexOf, every, filter, forEach, map, some, reduce, reduceRight, length]