const array = str.split(',');

MDN reference, mostly helpful for the possibly unexpected behavior of the limit parameter. (Hint: "a,b,c".split(",", 2) comes out to ["a", "b"], not ["a", "b,c"].)

Answer from Matchu on Stack Overflow
🌐
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.
Discussions

Convert comma separated string to a JavaScript array - Stack Overflow
I have this string: "'California',51.2154,-95.2135464,'data'" I want to convert it into a JavaScript array like this: var data = ['California',51.2154,-95.2135464,'data']; How do I do this? I d... More on stackoverflow.com
🌐 stackoverflow.com
[JavaScript] How to convert comma separated string into an array?
I want to convert a comma separated string into an array, how to do that in Javascript? More on onecompiler.com
🌐 onecompiler.com
1
December 27, 2021
javascript - How to convert string separated by commas to array? - Stack Overflow
Possible Duplicate: Convert JS object to JSON string Store comma separate values into array · I have a string containing values separated with commas: ... I didn't find any information about it in Google... ... JSON is a textual serialization of data. I have updated the question to reflect needing a JavaScript ... More on stackoverflow.com
🌐 stackoverflow.com
How to convert a comma-separated string into JS array?
let array = 'string'.split(','); Edit: MDN Documentation More on reddit.com
🌐 r/learnjavascript
1
2
August 4, 2020
🌐
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
You can use the JavaScript split() method to split a string using a specific separator such as comma (,), space, etc. If separator is an empty string, the string is converted to an array of characters.
🌐
Designcise
designcise.com › web › tutorial › how-to-convert-a-comma-separated-string-to-an-array-in-javascript
How to Convert a Comma-Separated String to an Array in JavaScript? - Designcise
September 16, 2022 - You can convert a JavaScript comma-separated string (which has no spaces) into an array by using the String.prototype.split() method, for example, like so:
🌐
W3docs
w3docs.com › javascript
How to Convert a Comma-Separated String into Array
Use a comma separator in the first ... by comma: ... Use the limit parameter to split a string into an array and also get the individual name. ... let str = "Rome,Moscow,Paris,Madrid,Prague,Milan"; let arr = str.split(",", 4); ...
🌐
Clue Mediator
cluemediator.com › convert-comma-separated-string-into-an-array-in-javascript
Convert comma separated String into an Array in JavaScript - Clue Mediator
January 10, 2020 - If we pass empty string ("") as the separator then each character will be splitted and converted into the array. var str = "How are you?"; var arr = str.split(""); console.log(arr); // Output: ["H", "o", "w", " ", "a", "r", "e", " ", "y", "o", "u", "?"] Thank you for reading.
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 - Using the split() Method (Most Common)The split() method is the simplest and most commonly used way to convert a comma-separated string into an array. It splits a string into an array based on a specified cha
🌐
SourceFreeze
sourcefreeze.com › home › how to convert comma separated strings to array in javascript
How to convert comma separated strings to array in JavaScript - Source Freeze
December 15, 2023 - When combined with the split() method, it offers an alternative approach to handle comma-separated strings. ... Now, we can leverage Array.from() to convert this string into an array of individual fruits by first splitting it using split(‘,’):
🌐
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.
🌐
GitHub
gist.github.com › 88d7d6d9e052a72e803b770dc1712b1a
Javascript: Convert comma separated string to array · GitHub
Javascript: Convert comma separated string to array · Raw · csvToArray.js · This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
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
🌐
Reddit
reddit.com › r/learnjavascript › how to convert a comma-separated string into js array?
r/learnjavascript on Reddit: How to convert a comma-separated string into JS array?
August 4, 2020 - let array = 'string'.split(','); Edit: MDN Documentation · Some useful JavaScript projects · r/learnjavascript • · upvotes · · comments · Most intuitive way to learn JS · r/learnjavascript • · upvotes · · comments · JavaScript ...
🌐
Codemia
codemia.io › home › knowledge hub › how can i convert a comma-separated string to an array?
How can I convert a comma-separated string to an array? | Codemia
January 8, 2025 - A CSV line can contain quoted commas, escaped quotes, and embedded newlines. For example, "New York, NY" is one field, not two. If the input is real CSV, use a CSV parser instead of plain string splitting. ... 1import csv 2from io import StringIO 3 4text = 'apple,"New York, NY",orange' 5row = next(csv.reader(StringIO(text))) 6print(row) JavaScript in Node.js usually relies on a CSV library for this case.
🌐
codestudy
codestudy.net › blog › how-can-i-convert-a-comma-separated-string-to-an-array
How to Convert a Comma-Separated String to an Array in JavaScript Using split() — codestudy.net
One frequent requirement is converting a comma-separated string (e.g., `"apple,banana,orange"`) into an array of individual values (e.g., `["apple", "banana", "orange"]`). The `split()` method is JavaScript’s built-in solution for this, and ...