How to check if a value is an Array in a scoped application
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-17-2020 08:47 PM
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.
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:
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-17-2020 08:56 PM
Hi,
you can use this
var arr = ['1','2','3'];
var val = Array.isArray(arr);
gs.info(val);
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader