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
Discussions

json - How to return comma delimited string from array, in React, javascript? - Stack Overflow
If it is the first item (index == 0), then just return the name to the accumulator (which kind of stores the string and appends to it as you go through the array) with quotation marks on either side (escaped with \ but not necessary if using single quotes), else return the accumulator with a comma ... More on stackoverflow.com
🌐 stackoverflow.com
How can I convert a comma-separated string to an array?
I have a comma-separated string that I want to convert into an array, so I can loop through it. Is there anything built-in to do this? For example, I have this string var str = "January,February, More on stackoverflow.com
🌐 stackoverflow.com
Convert string separated by comma in json object to array
I want to convert this json object that contain string value separated by comma to array: [ {id: 1, name: 'book', colors: 'red, yellow, blue' }, id: 2, name: 'book', colors: 'red, yel... More on stackoverflow.com
🌐 stackoverflow.com
JavaScript: How to get comma separated string from json string? - Stack Overflow
I have a JSON string value that corresponds to this object: { "id" : "122223232244", "title" : "התרעת פיקוד העורף", "data" : ["עוטף עזה 218","עוטף עזה 217"] } I am trying to extract the following... More on stackoverflow.com
🌐 stackoverflow.com
June 13, 2019
🌐
GeeksforGeeks
geeksforgeeks.org › convert-comma-separated-string-to-array-using-javascript
JavaScript – Convert Comma Separated String To Array | GeeksforGeeks
November 26, 2024 - However, arrays are mutable, allowing you to perform operations such as adding, removing, or modifying elements. Converting a string to an array makes it easier to:Access individual characters or substrings.Perform array operations su ... Given a 2D array, we have to convert it to a comma-separated values (CSV) string using JS.
🌐
OneCompiler
onecompiler.com › javascript › 3xfqsme8y
convert a json array of objects to comma separated values - JavaScript - OneCompiler
let mobiles = ["iPhone", "Samsung", "Pixel"] // accessing an array console.log(mobiles[0]) // changing an array element mobiles[3] = "Nokia"
🌐
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 :
🌐
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 - JavaScript fundamental (ES6 Syntax) exercises, practice and solution: Write a JavaScript program to convert a comma-separated value (CSV) string to a 2D array of objects. The first row of the string is used as the title row.
🌐
Medium
vijayendren-r.medium.com › javascript-react-js-function-to-convert-array-json-into-a-csv-file-8315ea8f6ab2
JavaScript(React JS) Function to convert Array/JSON into a CSV file. | by Vijayendren R | Medium
January 5, 2021 - // Function to convert the JSON(Array of objects) to CSV. const arrayToCsv = (headers, data) => { const csvRows = []; // getting headers. const headerValues = headers.map(header => header.label); csvRows.push(headerValues.join(’,’)); // Push into array as comma separated values // Getting rows. for (const row of data) { const rowValues = headers.map(header => { const escaped = (’' + row[header.key]).replace(/"/g, '\\"’); // To replace the unwanted quotes. return `"${escaped}"`; // To escape the comma in a address like string.
Find elsewhere
🌐
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.
🌐
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.
🌐
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.
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › convert-comma-separated-string-to-array-using-javascript
JavaScript - Convert Comma Separated String To Array - GeeksforGeeks
July 11, 2025 - The split() method is the simplest and most commonly used way to convert a comma-separated string into an array.
🌐
n8n
community.n8n.io › questions
Json to array comma - Questions - n8n Community
May 16, 2022 - Hello everyone. I trying to convert a json data to a string comma separated. Json is like this one: [ { "id": "625d757724acbe52634e6172", "idBoard": "625850ac4247c214ff3dc167", "name": "ANGELIS", …
🌐
Reddit
reddit.com › r/webdev › [javascript] how to effectively convert string to array while removing commas and the space at the beginning/end if there was any?
r/webdev on Reddit: [javascript] how to effectively convert string to array while removing commas and the space at the beginning/end if there was any?
September 14, 2021 -

i think this can be done by regEx by i don't how to look it up.

this is a learning project, but i am just thinking about the scale

i have a form where the user enter a bunch of categories and i want the user to separate those categories with a comma, but working on the case where the user add the comma but also a space after the comma (as we all do) or before the comma, how to go about treating this case, because i don't want to end up with two or three categories that are the same.

edit: i did it but i don't want to remove the post to help anyone with the same issue.

here's what i did

const categoriesAsString = e.target.value;

const categoriesTrimmed = categoriesAsString.trim();

const categoriesAsStringWithWhiteSpace = categoriesTrimmed.replace(/\s*,\s*/g,",");

const categoriesAsArray = categoriesAsStringWithWhiteSpace.split(",");

setCategories(categoriesAsArray);