Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

How to check Object is inside Array Or not

Sironi
Kilo Sage

Hi All,

How to check below Obj is inside Array or not


1. obj={"id":"1101"}   

return Obj;


2. Obj=[{"id":"1101"}]

return Obj;

How do we know return "Obj " is in inside Array Or not.


 

 

3 REPLIES 3

SanjivMeher
Mega Patron
Mega Patron

Can you try using isArray and see if that works?

https://www.w3schools.com/jsref/jsref_isarray.asp

 

Ex, I tried this in background script, which returns false.

var Obj={"id":"1101"}
gs.info(Array.isArray(Obj));
 
And this returns true
var Obj=[{"id":"1101"}]
gs.info(Array.isArray(Obj));

Please mark this response as correct or helpful if it assisted you with your question.

Thanks Sanjay !, it is working as expected.

Awesome. Could you please mark my response correct if it worked for you?


Please mark this response as correct or helpful if it assisted you with your question.