Empty array's length is 1

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-30-2020 08:22 AM
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
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-30-2020 08:29 AM
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');
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-30-2020 09:28 AM
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.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-30-2020 11:34 AM
If this has answered your question, kindly mark the comment as a correct answer so that the question is moved to the solved list.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-26-2024 07:30 AM
Hi,
were you able to solve this? I am having the same issue.