This will convert it into an array (which is the JSON representation you specified):

var array = myString.split(',');

If you need the string version:

var string = JSON.stringify(array);
Answer from joeltine on Stack Overflow
🌐
W3Resource
w3resource.com › javascript-exercises › fundamental › javascript-fundamental-exercise-4.php
JavaScript fundamental (ES6 Syntax): Convert a comma-separated values string to a 2D array of objects - w3resource
July 3, 2025 - const CSV_to_JSON = (data, delimiter = ',') => { // Extract titles from the first row of the CSV data. const titles = data.slice(0, data.indexOf('\n')).split(delimiter); // Split the CSV data by newline characters, map each row to a JSON object with titles as keys. return data .slice(data.indexOf('\n') + 1) .split('\n') .map(v => { const values = v.split(delimiter); // Create a JSON object using titles and corresponding values. return titles.reduce((obj, title, index) => ((obj[title] = values[index]), obj), {}); }); }; // Test cases console.log(CSV_to_JSON('col1,col2\na,b\nc,d')); // [{'col1':
Find elsewhere
🌐
LinkedIn
linkedin.com › pulse › javascript-function-convert-comma-separated-values-string-milap-patel-1c
JavaScript Function To Convert A Comma-Separated Values String Into JSON !
August 18, 2023 - In this video, you will learn JavaScript Function To Convert A Comma-Separated Values String Into JSON ! 🔔 Subscribe for more videos like this :
🌐
GeeksforGeeks
geeksforgeeks.org › convert-comma-separated-string-to-array-using-javascript
JavaScript – Convert Comma Separated String To Array | GeeksforGeeks
November 26, 2024 - In pyspark SQL, the split() function converts the delimiter separated String to an Array. Â It is done by splitting the string based on delimiters like spaces, commas, and stack them into an array.
🌐
OneCompiler
onecompiler.com › javascript › 3xfqsme8y
convert a json array of objects to comma separated values - JavaScript - OneCompiler
Executable in both browser and server which has Javascript engines like V8(chrome), SpiderMonkey(Firefox) etc. var readline = require("readline") var rl = readline.createInterface({ input: process.stdin, output: process.stdout, terminal: false, }) rl.on("line", function (line) { console.log("Hello, " + line) }) ... An array is a collection of items or values.
🌐
Tutorial Republic
tutorialrepublic.com › faq › how-to-convert-comma-separated-string-into-an-array-in-javascript.php
How to Convert Comma Separated String into an Array in JavaScript
The following example demonstrates how to convert a comma separated string of person name into an array and retrieve the individual name using JavaScript.
🌐
Microsoft Power Platform Community
powerusers.microsoft.com › t5 › Building-Flows › JSON-received-as-a-comma-separated-string-need-help-in › td-p › 676482
https://powerusers.microsoft.com/t5/Building-Flows...
Quickly search for answers, join discussions, post questions, and work smarter in your business applications by joining the Microsoft Dynamics 365 Community.
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › convert-comma-separated-string-to-array-using-javascript
JavaScript - Convert Comma Separated String To Array - GeeksforGeeks
July 11, 2025 - The reduce() function builds an array by concatenating characters until a comma is encountered. You can manually process the string using loops and the slice() method to extract substrings.
Top answer
1 of 3
1
One would 1st call the string's · split · method: · var list = ' item 1, item 2 , ,item 3 '; · var array = list · .split(','); · gs.debug('\n[' + array.join(']\n[') + ']'); · This prints: · *** Script: [DEBUG] · [ item 1] · [ item 2 ] · [ ] · [item 3 ] · Pretty all over the place. · For better result - where the leading and trailing spaces are removed - one would use · trim · before splitting: · var list = ' item 1, item 2 , ,item 3 '; · var array = list · .trim() · .split(','); · gs.debug('\n[' + array.join(']\n[') + ']'); · *** Script: [DEBUG] · [item 1] · [ item 2 ] · [ ] · [item 3] · Really only slightly better - only the 1st and the last items look good - and half of both only by chance (the one who entered the list did not add extra spaces after the last item and before the 1st one). · To take care of all extra spaces for all items that could exist due to sloppy fellow programmers composing the list or faulty data entry, one would switch the splitter to · RegExp · : · var list = ' item 1, item 2 , ,item 3 '; · var array = list · .trim() · .split(/\s*,\s*/g); · gs.debug('\n[' + array.join(']\n[') + ']'); · *** Script: [DEBUG] · [item 1] · [item 2] · [] · [item 3] · A lot better, almost there, just one problem remains: the 3rd item which is empty. · To take care of that problem one might · filter · the resulting array: · var list = ' item 1, item 2 , ,item 3 '; · var array = list · .trim() · .split(/\s*,\s*/g) · .filter(retainNotEmpty); · function retainNotEmpty (item) { · return '' != item; · } · gs.debug('\n[' + array.join(']\n[') + ']');​ · *** Script: [DEBUG] · [item 1] · [item 2] · [item 3] · Just about what one desires. · Filtering will also fix the issue of empty string ending up (not in a 0 length array, but) in an array with one item when split.
2 of 3
0
Hi @hardikbendre , · Please use the below to convert comma separated value into an array: · // dec stores the comma separated values · var dec = "service,now,community" · var colSplit = dec.split(","); · var arr=[]; · for(i=0;i