Remove double quotes from array values

Bhaskar3
Tera Expert

I am getting the response in Client Script from the Script Include as below.

["5390f47f97e892545a4b31511153af96","2a21e73697709e901b85f0511153afce","42c87060471e46d0fcf52501e36d436f"]

 

I would like to convert it as below by removing the double quotes.

[5390f47f97e892545a4b31511153af96,2a21e73697709e901b85f0511153afce,42c87060471e46d0fcf52501e36d436f]

 

Please help me to achieve this by adding the piece of code in Script Include or Client Script.

1 ACCEPTED SOLUTION

Bhaskar3
Tera Expert

Below code worked.

var arr = ["5390f47f97e892545a4b31511153af96","2a21e73697709e901b85f0511153afce","42c87060471e46d0fcf52501e36d436f"];
arr = arr.toString().replaceAll('"',"").trim();

View solution in original post

4 REPLIES 4

Bert_c1
Kilo Patron

Once you post your Script Include and Client script, folks here will be able to assist. See:

 

10-tips-for-writing-a-quality-community-question

 

 

 

Viraj Hudlikar
Giga Sage

Hello @Bhaskar3 

 

You can achieve this by parsing the JSON string and then converting it back to an array without quotes. Here's a simple way to do this in a Client Script:

 

var response = '["5390f47f97e892545a4b31511153af96","2a21e73697709e901b85f0511153afce","42c87060471e46d0fcf52501e36d436f"]';

// Parse the JSON string to an array
var parsedArray = JSON.parse(response);

// Convert the array to a string without quotes
var resultArray = parsedArray.map(function(item) {
    return item;
});

//gs.log(resultArray); // Output: [5390f47f97e892545a4b31511153af96, 2a21e73697709e901b85f0511153afce, 42c87060471e46d0fcf52501e36d436f]

 

This script parses the JSON string into an array and then maps each item to a new array, effectively removing the quotes. The gs.log statement will display the array in the desired format.

If my response has helped you hit helpful button and if your concern is solved do mark my response as correct.

 

Thanks & Regards
Viraj Hudlikar.

Hello @Bhaskar3 

 

Any issue with my solution provided?

 

If my response has helped you hit helpful button and if your concern is solved do mark my response as correct. 

As per new feature on community you can mark multiple answers as correct.

 

Thanks & Regards

Viraj Hudlikar.

Bhaskar3
Tera Expert

Below code worked.

var arr = ["5390f47f97e892545a4b31511153af96","2a21e73697709e901b85f0511153afce","42c87060471e46d0fcf52501e36d436f"];
arr = arr.toString().replaceAll('"',"").trim();