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.
🌐
GeeksforGeeks
geeksforgeeks.org › create-a-comma-separated-list-from-an-array-in-javascript
Create a Comma Separated List from an Array in JavaScript | GeeksforGeeks
December 28, 2024 - The code uses map(String) to convert each element of the array arr into a string, and then join(',') joins these string elements with commas. The result is a comma-separated string "1,2,3,4,5", which is logged to the console.
🌐
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.
🌐
W3docs
w3docs.com › javascript
How to Convert a Comma-Separated String into Array
Use a comma separator in the first argument of the split method if you want to split it by comma: ... Use the limit parameter to split a string into an array and also get the individual name.
🌐
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.
🌐
StackHowTo
stackhowto.com › home › web development › javascript › how to convert comma separated string into an array in javascript
How to Convert Comma Separated String into an Array In JavaScript - StackHowTo
October 12, 2021 - Youou can simply utilize the split() method of JavaScript to split a string using a particular separator, such as comma (,), space, etc. If the separator is an empty string, it is converted to an array of characters.