After receiving the following input:
const myString = "['one', 'two']";
When I use this command:
console.log(typeof myString);
The output is string
.
Although it's expected due to the nature of the input, I now need to convert this string into an array of strings.
For instance:
const myArray = ['one', 'two'];
So, after running:
console.log(typeof myArray);
The result should be object
.
I've attempted to use JSON.parse()
and JSON.stringify
, but without success.
The main question here is how can I (in JavaScript) change a string array into an array of strings?