- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-04-2015 08:54 AM
Hi All,
I am struggling in adding elements of an array. I am using the below script.
while(ish.next())
{
lan1.push(ish.u_lan);
}
for(var i = 0 ; i< lan1.length; i++)
{
var lan2 = parseInt(lan1[i]);
gs.log(lan2,"lan2");
lan += lan2;
gs.log(lan,"lan");
}
The above script is adding the only one value means in the log for "lan2" i am getting the same number , may be it is the last number in the array. Please help me to adding the numbers in the array successfully.
Thanks & Regards,
Swamy
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-06-2015 12:38 AM
Hi Kalai,
Thank you so much for your respone.
If i used .toString method then it is appending the value instead of summing up (like a[0] =1 and a[0] =2 then then if i perform sum operation it is giving 12 instead of 3). I have used Number(ish.u_lan), and it worked.
Regards,
Swamy

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-04-2015 10:11 AM
Use toString() or getValue
while(ish.next())
{
lan1.push(ish.u_lan.toString());
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-06-2015 12:38 AM
Hi Kalai,
Thank you so much for your respone.
If i used .toString method then it is appending the value instead of summing up (like a[0] =1 and a[0] =2 then then if i perform sum operation it is giving 12 instead of 3). I have used Number(ish.u_lan), and it worked.
Regards,
Swamy

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-04-2015 10:15 AM
And the legend himself mark.stanger had answered me. And, it was my first post/comment here
Bug while using background script