Why Array Map function not works

ericpan
Kilo Explorer

Hi,

I tested the following script on browsers (changed gs.print to console.log), it was okay. However, it returned error on ServiceNow when I tried to run it in Background Script. It seems that Array Map function is not working. Anyone knows why?

The Script:

var keywords = ['A', 'B', 'C'];

var parts_name = keywords.map(function (item) {return item + '; ';});

gs.print(parts_name[0], parts_name[1], parts_name[2]);

The error returned:

Javascript compiler exception: The undefined value has no properties. (<refname>; line 3) in:

var keywords = ['A', 'B', 'C'];

var parts_name = keywords.map(function (item) {return item + '; ';});

gs.print(parts_name[0], parts_name[1], parts_name[2]);

Thank you very much,

Eric Poon

1 ACCEPTED SOLUTION

edwin_munoz
Mega Guru

Hello Eric,



On this link you can see that Map Array is supported by most browsers, however, it is not supported by IE on versions prior to 9. I have found that ServiceNow offers similar support for javascript as IE 8 (Maybe 7), there are multiple native methods that you will not be able to use in ServiceNow and you will need to find a workaround.


View solution in original post

1 REPLY 1

edwin_munoz
Mega Guru

Hello Eric,



On this link you can see that Map Array is supported by most browsers, however, it is not supported by IE on versions prior to 9. I have found that ServiceNow offers similar support for javascript as IE 8 (Maybe 7), there are multiple native methods that you will not be able to use in ServiceNow and you will need to find a workaround.