At the time of writing, the Apps Script JavaScript engine is based on ES3 with a few useful ES5 things added. Much of the rest of the world is at Es6 with Es7 coming along. Much of Es6 needs new syntax that isn’t supported by the Apps Script IDE, but a lot of the goodies can be emulated using a Shim which will allow you to use them by translating them back into the earlier version of JavaScript.

Paul Miller has a nice Es6-shim ready for browser use, so I made a couple of very minor tweaks to get it working with Apps Script, and here’s the library that you can use to start to bring ES6 goodness into Apps Script while waiting for it to become native. The good thing about this approach is that when it does become native, you’ll won’t need to change a thing – just stop using the libraries.

The library is cEs6Shim, and you’ll find it here 1dvi84vwjD03YUc_-yp4D_fFjIXTK0J8Zk93qtNTPDI0xe2NO35XSv9em or on Github if you want to make your own copy. Right now it’s not minimized but I’ll add a minimized version at some future point.

What can you do with Es6.

There are lots of tutorials out there, so rather than repeat them here, you can go and take a look. Remember that any syntactical changes such as {…args} and for .. of won’t be able to work in the Apps Script IDE, but most of the additional methods will and have been implemented in this library. Here’s some examples following. In some cases I’ve shown how you can achieve the same thing in vanilla JavaScript.

Setting up

You need the library (or your own copy in your project). If you are using the library, you’ll need a couple of local references for the Map and Set object if you plan to use them, as follows

Array methods

// we can use Array.from to convert iterators to an array, since we dont have the for … of syntax
Logger.log (Array.from (arr.keys())); //[0.0, 1.0, 2.0, 3.0, 4.0] Logger.log (Array.from (arr.values())); // [a, b, c, d, e]

String methods

Maps

Sets

For more like this see Google Apps Scripts Snippets
Why not join our community , follow the blog, twitter, G+ .You want to learn Google Apps Script?