Empty array's length is 1

Rohit Agarwal
Mega Expert

Hi,

In case of empty array, the length is showing as 1. Can anyone suggest why and how to fix this

var ciRelArray = new Array();
var ciRelArrayValue = new Array();
ciRelArray = this.chgRelatedCI(current).toString();
ciRelArrayValue = ciRelArray.split(',');
if (ciRelArrayValue.length != 0)

gs,log('test');
}

Thanks

4 REPLIES 4

Ct111
Tera Sage

Before making any conclusion that it is one , print it and see.

var ciRelArray = new Array();
var ciRelArrayValue = new Array();
ciRelArray = this.chgRelatedCI(current).toString();
ciRelArrayValue = ciRelArray.split(',');

gs.info('Lengthof RelArrVal is'+ciRelArrayValue.length);


if (ciRelArrayValue.length != 0)

gs.log('test');
}

 

asifnoor
Kilo Patron

Hi Rohit,

Try this code

var ciRelArray = this.chgRelatedCI(current).toString();
var ciRelArrayValue = ciRelArray.split(',');
if (ciRelArrayValue.length != 0)
{ 
  gs.log('test');
} else {
  gs.log('Nothing to split with comma');
}

Mark the comment as a correct answer if this solves the problem.

If this has answered your question, kindly mark the comment as a correct answer so that the question is moved to the solved list.

sayalisheth
Tera Contributor

Hi,

were you able to solve this? I am having the same issue.