You can use Array.concat(), since concat accepts both arrays and non arrays:

const names = (v) => [].concat(v).map(name => name.toUpperCase())

console.log(names(['Bart', 'Lisa'])) // [ 'BART', 'LISA' ]
console.log(names('Homer')) // ['HOMER']

Answer from Ori Drori on Stack Overflow
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ javascript โ€บ string-to-array-in-javascript
JavaScript - Convert String to Array - GeeksforGeeks
August 5, 2025 - Once converted, we can apply the map() method to manipulate or transform each character in the string. ... Array.prototype.map: The array method used to create a new array by applying a function to each element. call: Allows the use of array methods on array-like objects (such as strings).
๐ŸŒ
PyTutorial
pytutorial.com โ€บ javascript-convert-string-to-array
PyTutorial | JavaScript Convert String to Array
July 29, 2026 - You can also check the JavaScript Array Length Guide to understand how to work with array sizes. Avoid these common mistakes when converting strings to arrays. ... // Forgetting the separator returns the whole string as one element let str = "hello"; let arr = str.split(); console.log(arr); // Output: ["hello"]
๐ŸŒ
DEV Community
dev.to โ€บ sanchithasr โ€บ 6-ways-to-convert-a-string-to-an-array-in-javascript-1cjg
6 Ways to Convert a String to an Array in JavaScript - DEV Community
September 24, 2022 - Converting from string to array is always done using the split() method but after ES6, there are many tools we could do the same. Letโ€™s go through each method one by one and discuss the pros and cons of each.
๐ŸŒ
Favtutor
favtutor.com โ€บ articles โ€บ string-to-array-javascript
Convert String to Array in JavaScript (4 Easy Methods)
November 11, 2023 - As the output shows, the array contains only one element as there is no comma delimiter, hence the string components are not separated. One of the easiest methods to convert a string to an array in JavaScript is by using the Array.from() method. ...
๐ŸŒ
Board Infinity
boardinfinity.com โ€บ blog โ€บ string-to-array-conversion-in-javascript
String to Array conversion in JavaScript | Board Infinity
June 13, 2026 - There is just a single method that is quite famous and widely used in JavaScript for turning a String into an array in JS and that is the .split() method. This method divides a string into an array of other strings, using a particular character, ...
๐ŸŒ
DEV Community
dev.to โ€บ hrishikesh1990 โ€บ how-to-convert-a-string-to-an-array-in-javascript-54g1
How to convert a string to an array in javascript? - DEV Community
June 1, 2021 - While using the split to convert string to array in JavaScript, keep in mind that it only returns an array and that the original string still remains a string. If no delimiter is passed the entire string is returned as one element in an array and if an empty string "" is passed, the string splits each character and an array.
๐ŸŒ
airbrake
docs.airbrake.io โ€บ home โ€บ blog โ€บ javascript error handling โ€บ javascript: how to convert a string into an array
JavaScript: How To Convert a String Into an Array - Airbrake Docs
January 19, 2022 - The split() method is one of the most popular ways JavaScript developers convert their strings into arrays. When using a split() within a string, the substring returns as an array.
Find elsewhere
๐ŸŒ
SamanthaMing
samanthaming.com โ€บ tidbits โ€บ 83-4-ways-to-convert-string-to-character-array
4 Ways to Convert String to Character Array in JavaScript | SamanthaMing.com
Which means we have an Array PLUS some string methods. This is more evident if we use the TypeScript Playground. Feel free to copy the code and paste in the playground, where you can hover on the variable to view the types. Since this is just an article, I'll paste the result here so you can follow along. const word = 'word'; const usingSplit = string.split(''); const usingSpread = [...string]; const usingArrayFrom = Array.from(string); // Result: // string[] ๐Ÿ‘ˆ Which means it's an Array of strings
๐ŸŒ
CodingNomads
codingnomads.com โ€บ javascript-array-to-string-conversion
JavaScript Array-String Conversion
It's denoted by three dots ... and is used in a variety of contexts, including destructuring and function arguments. The spread operator can be used to convert a string to an array.
๐ŸŒ
TutorialsPoint
tutorialspoint.com โ€บ article โ€บ converting-string-to-an-array-in-javascript
Converting string to an array in JavaScript
March 15, 2026 - <!DOCTYPE html> <html> <head> <title>Converting string to an array in JavaScript</title> <script> let string = "Tutorix"; let arr = Array.from(string); document.write("Array from string: " + arr); </script> </head> <body> </body> </html> ... The spread operator (...) provides a concise way to convert strings to character arrays by expanding each character as a separate element. Without the spread operator, a string would be treated as a single element:
๐ŸŒ
LinkedIn
linkedin.com โ€บ pulse โ€บ ways-convert-string-array-javascript-joseph-ejiro
Ways to convert string to Array in JavaScript
September 29, 2023 - you can use destructuring() method to covert a string into an array by declaring a string, using square brackets [] on the left side of the assignment operator = and then prepend the string variable with three dots ... to spread it into individual ...
Top answer
1 of 3
1

You could use the following string splitting approach:

var data = '[[Bday Party , 2023-05-16], [Bday Party , 2023-05-16], [Bday Party , 2023-05-16], [Bday Party , 2023-05-16], [Bday Party , 2023-05-16], [Bday Party , 2023-05-16]]';
data = data.substring(2, data.length - 2);
var array = data.match(/\[.*?\]/g);
var output = [];
for (var i=0; i < array.length; ++i) {
    output.push(array[i].substring(1, array[i].length - 1).split(/\s*,\s*/));
}
console.log(output);

2 of 3
1

It's not perfect but should get the jobs done:

const data = '[[Bday Party , 2023-05-16], [Bday Party , 2023-05-16], [Bday Party , 2023-05-16], [Bday Party , 2023-05-16], [Bday Party , 2023-05-16], [Bday Party , 2023-05-16]]';

const json = JSON.parse(data.replace(/\s*([^[\],]+?)\s*(?=[,\]])/g, '"$1"'));

console.log(json);

How the regex works:

\s*([^[\],]+?)\s*(?=[,\]])

Here you can see how it works and play around a little bit

syntax explain
\s* any white spaces, this is for getting rid of the leading spaces from each entry
( group one start, this is for capturing each entry, such as Bday Party
[^[\],]+? 1 or more characters that does not contain [, ] and ,. +? means 1 or more but non-greedy, this is for avoiding capturing trailing spaces (we can't rule out white spaces inside of the character set, since some of the entries contains white spaces in the middle)
) group one end, so far we have captured the entry we need in group one, such as Bday Party
\s* any trailing whitespaces after an entry, we don't need that in our capturing group
(?=[,\]]) a lookahead, everything we have matched must be followed by a ,(list separator) or ](end of an array)
๐ŸŒ
YouTube
youtube.com โ€บ watch
JavaScript split() and join() Method Explained Step by Step: Convert Strings to Arrays (and Back!) - YouTube
Need to convert a string into an array or stitch an array back into a single string? JavaScript provides the perfect pair: .split() and .join(). In this tuto...
Published: April 10, 2025
๐ŸŒ
Stack Abuse
stackabuse.com โ€บ how-to-convert-a-string-to-an-array-in-javascript
How to Convert a String to an Array in JavaScript
May 22, 2023 - Additionally, the Array.from() method supports emoji characters: let word = "It is sweet ๐Ÿ˜‹"; let wordChars = Array.from(word) console.log(wordChars); // ["I","t"," ","i","s"," ","s","w","e","e","t"," ","๐Ÿ˜‹"] The Spread Operator has several uses and is a widely-applicable operator in JavaScript.
๐ŸŒ
Plain English
plainenglish.io โ€บ home โ€บ blog โ€บ javascript โ€บ 5 ways to convert string to array in javascript
5 Ways to Convert String to Array in JavaScript
November 23, 2020 - let str = 'jscurious'; let arr = Array.from(str, (val, index) => val + index); // adding index value to each element of array console.log(arr); // ["j0", "s1", "c2", "u3", "r4", "i5", "o6", "u7", "s8"] The spread operator (โ€ฆ) extracts and spreads each character of a String. We can just wrap all those characters inside an array literal to create a new array from the string. let str = 'jscurious'; let arr = [...str]; console.log(arr); // ["j", "s", "c", "u", "r", "i", "o", "u", "s"] This method is used to copy the values and properties from one or more source objects to a target object.
๐ŸŒ
YouTube
youtube.com โ€บ tech industry analysis
Converting a String into an array using JavaScript - YouTube
To convert a string into an array use the split() function. This "splits" each character in a string as an indexed item within an array. Moreover, this enabl...
Published: April 14, 2022
Views: 2K
๐ŸŒ
Stack Overflow
stackoverflow.com โ€บ questions โ€บ 55949470 โ€บ to-convert-a-string-to-array-in-javascript
TO convert a string to array in javascript - Stack Overflow
Possible duplicate of Convert string in array format to javascript array and Parsing string as JSON with single quotes? ... Save this answer. ... Show activity on this post. ... var str = "['one','two']"; str = str.replace( /[\[\]']+/g, '' ); var strarr = str.split( ',' ); console.log( strarr )
๐ŸŒ
GoLinuxCloud
golinuxcloud.com โ€บ home โ€บ programming โ€บ javascript โ€บ convert string to array javascript (split, array.from, unicode)
Convert string to array JavaScript (split, Array.from, Unicode)
June 16, 2026 - Converting a string into an array splits into two common jobs: tokenize by delimiter (split with a string or regex), or expand into per-character or per-code-point elements (Array.from, spread, or for...of). Use split when you already know the separators; use iterators when you care about Unicode code points or emoji that split('') would break. The spread operator in JavaScript is a concise way to materialize iterator results.