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

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

Hi @Ankur Bawiskar 

Thank you for responding.

Is there a way of checking 'arr' CONTAINS 'Invalid' keyword?
I tried with Encoded query but, it does not work.

Hi,

Did I answer your original question for array empty or not?

If my response helped please mark it correct and close the thread so that it benefits future readers.

regards
Ankur

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

Hi Ankita,

you can use ArrayUtil class to search if array contains some element

ArrayUtil - Global

Regards
Ankur

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