- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-16-2021 06:59 AM
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
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-16-2021 07:42 AM
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);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-16-2021 07:11 AM
Hi,
ideally when you declare an array every element is wrapped with double quotes or single quote
the example for array you shared is not the correct way to declare it
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-16-2021 07:27 AM
Yes you are correct but im getting the value like that so asked is there any way?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-16-2021 07:34 AM
Hi,
so you can get the array value and then split them
how and from where the array is getting populated?
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-16-2021 07:42 AM
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);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-16-2021 12:25 PM
try below
var ar=[];
var as="servicenow";
var ab="community";
ar.push('"'+as+'"');
ar.push('"'+ab+'"');
gs.print(ar.toString());