I have the following input which I receive:
const myString = "['one', 'two']";
When I run the following command:
console.log(typeof myString);
I get string
This makes sense, as this is a string input. The input type is out of my control, I must receive this as a typeof string.
However, I would like to convert this string, into a formal array of strings.
For example:
const myArray = ['one', 'two'];
So, when I run:
console.log(typeof myArray);
I get object
.
I have tried JSON.parse()
and JSON.stringify
but to no luck.
The basics of my question are how do I (in JavaScript) convert a string array, into an array of strings?