How to check if a value is an Array in a scoped application

Joe83
Kilo Contributor

Hi ServiceNow Community Developers,

I have a very strange situation - I am trying to check if the field value is an array or not by using the Array.isArray() method however I am getting mixed results depending on where I am executing it from. For instance I wrote the following script which I am running as a background script and it is working as expected, it gives me the expected results all the time. I  can change the variable I am passing to the function and I always get what I expect to get.

find_real_file.png

However the following function inside a script include is always returning false even if the passed value is array and I am not sure what is it I am doing wrong. 

Here is the function:

find_real_file.png

The text that I passed to the above function is as follows: [1,2,3]

Since this text is clearly an array I expect the function to return true however it's always returning false. 

I am out of ideas now as to why this is not working as expected. Please take a look and kindly advise.

Thanks,

John

1 REPLY 1

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

you can use this

var arr = ['1','2','3'];

var val = Array.isArray(arr);

gs.info(val);

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader