9
I have a string representing an array as follows:
var = "['aaaaa', 'bbbbb', 'ccccc', 'ddddd']";
Wish I could transform this array that is in the string into an Array to perform manipulations.
var = ['aaaaa', 'bbbbb', 'ccccc', 'ddddd'];
Thanks in advance.
I believe that do
var string = "['aaaaa', 'bbbbb', 'ccccc', 'ddddd']".replace(/\'/g, "\"")
make it a little simpler for the treatment of string.– Woss
@Andersoncarloswoss this way is also good. I have idea that I started to use
split/join
after tests where I saw it was faster. But in this case it is probably irrelevant.+1
– Sergio
@Andersoncarloswoss changed, your suggestion made me go for a quick test (https://jsfiddle.net/3L5etu88/) and in fact
replace
it’s much better.– Sergio