Convert String to array

amala2
Mega Guru

I have 2 strings which contains comma separated sysid values.I want to calculate the difference between the 2 strings ..I am trying to acheive this using the diff function in the ArrayUtil.

To acheive this , how to convert string to array?

1 ACCEPTED SOLUTION

Bryan Tay3
Mega Guru

hi amala,



u can try using Javascript's split function.



JavaScript String split() Method


View solution in original post

3 REPLIES 3

Bryan Tay3
Mega Guru

hi amala,



u can try using Javascript's split function.



JavaScript String split() Method


Zeeshan Khan1
Kilo Guru

Hi Amala,



If you have two strings which contains comma separated sys id, you can create an Array and find difference using below code :



var arr1 = str1.split(',');


var arr2 = str2.split(',');



var arrUtil = new ArrayUtil();


gs.print(arrayUtil.diff(arr1, arr2));



Note that this will return item from arr1 that were not found in arr2



Thanks,


Mohammed Zeeshan


Harsh Vardhan
Giga Patron

Hi Amala,



can you please share your code? i can try and give you the exact output that you need.


by the way you can refer the link below.



JavaScript string to array conversion - Stack Overflow



Thanks,


Harshvardhan