Welcome to Community Week 2025! Join us to learn, connect, and be recognized as we celebrate the spirit of Community and the power of AI. Get the details  

How to check in array has more then one value

lucky24
Tera Contributor

Hi Team,

I am storing value in array and I have to check array has more then one value.

If array has only one value then I have to store value in choice field but If array has more then value then I have to store in list collector.

var asm = new GlideRecord('asmt_metric_result');
asm.addQuery('metric.name','Improvement');
asm.addQuery('instance',current.sys_id); //
asm.query();
while(asm.next()) {
arr.push(asm.string_value +",");
}

How can I check array has more then one value or one value and store according validation?

Please help me here? 

3 REPLIES 3

piyushsain
Tera Guru

Hi @lucky24 

Use arr.length>1 to check if it has more than 1 value

If my answer has helped with your question, please mark my answer as accepted solution and give a thumb up.
Regards,
Piyush Sain

Harish KM
Kilo Patron
Kilo Patron

Hi @lucky24 you can use length() method to see how many values are present in array.

arr.length --> this will give you the total array values,  so you can check arr.length>1 // to check more than one value

Regards
Harish

Addy22
Tera Guru

Hi,

 

You can use if(arr.length>1){}