Array map - compilation error

Not applicable
var array1 = [1, 4, 9, 16];
// pass a function to map
const map1 = array1.map(x => x * 2);
console.log(map1);
// expected output: Array [2, 8, 18, 32]

doesn't work on Apigee cloud. Looks like array.map is throwing compilation errors.

Is that a known issue with Rhino?

Thanks,
Maruti

0 1 74
1 REPLY 1

Yes

Rhino is not fully ES6 compliant. You can example all the compatibility tests here:

http://mozilla.github.io/rhino/compat/engines.html

It's not Array.map. The shorthand arrow function syntax is the problem.

Try this:

var array1 = [1, 4, 9, 16];
// pass a function to map
const map1 = array1.map(function(x) { return x * 2; });
console.log(map1);
// expected output: Array [2, 8, 18, 32]