How to add double quotes to array values

Shalani Rajendr
Tera Contributor

Hi All,

I need to add double quotes to values in an array please help me on how to do that.

Example: var arr=["servicenow,community"];

I have an array like this but i need the array as var arr=["servicenow","community"]; via server script

Please tell me on how to solve this

 

1 ACCEPTED SOLUTION

Vitali1
Tera Expert

It looks like you have a value as a string but need to have multiple values instead.
You could try to split this string into multiple values before putting it in the array.
try this one

var someValue = "servicenow,community";
arr = someValue.split(',');
gs.print(arr);

View solution in original post

14 REPLIES 14

Hi Upender ,
I need to convert my script as 
""+table+"'",""+query+""


Is it possible?
If not , is their any way to achieve it?

 


If my response finds helpful, please indicate its helpfulness by selecting Accept as Solution and Helpful.

Thanks,

Vaibhav Nikam

Hi Shalani,

If array is like that arr=["servicenow,community"], means it is having only one element.

Then you can try as below

arr=["servicenow,community"]

gs.print(arr)

var arr1=arr[0].split(",");

gs.print(arr1)

Now arr1 become the array of two elements.

 

If my answer replied your question please mark appropriate response as correct so that the question will appear as resolved for other users who may have a similar question in the future.

Regards,
Saurabh


Thanks and Regards,

Saurabh Gupta

No it dint work sorry!

 

It is working if you are getting an array with single element. You want to seperate it, below code is working.

If you are expecting something else then please elaborate more.

Run the below code in background script

arr=["servicenow,community"]

gs.print(arr+": "+arr.length)

var arr1=arr[0].split(",");

gs.print(arr1+": "+arr1.length)

 

Output:
find_real_file.png

 

If my answer replied your question please mark appropriate response as correct so that the question will appear as resolved for other users who may have a similar question in the future.

Regards,
Saurabh


Thanks and Regards,

Saurabh Gupta

It is working if you are getting an array with single element. You want to seperate it, below code is working.

If you are expecting something else then please elaborate more.

Run the below code in background script

arr=["servicenow,community"]

gs.print(arr+": "+arr.length)

var arr1=arr[0].split(",");

gs.print(arr1+": "+arr1.length)

 

Output:
find_real_file.png

 

If my answer replied your question please mark appropriate response as correct so that the question will appear as resolved for other users who may have a similar question in the future.

Regards,
Saurabh


Thanks and Regards,

Saurabh Gupta