How to check if Array if it is null or undefined?

Ankita9
Tera Contributor

Hi All,

Can someone please advice, How can we check if Array if it is null or undefined in Transform map OnAfter Script?

 

 

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

you can check if array is empty

var arr = ['a','b'];

if(arr.length ==0){

// empty

}

Regards
Ankur

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

View solution in original post

6 REPLIES 6

Hi @Ankita 

What did you try in encodedquery?

One option is to use:

if(arr.indexOf('invalid') > -1){

//goes inside if, when invalid is present in the array arr

}else{

//when invalid is not present in the array arr

}

 


Feel free to mark correct, if your issue has been resolved, so it ends up in solved queue.

Will be helpful for others looking for the similar query.

Best Regards
Aman Kumar

Kieran Anson
Kilo Patron

Hi Ankita,

You can use the available OOB script includes JSUtil

JSUtil.isEmpty()