How can you parse this string "['option1', 'option2']" into array?
I don't have 50 reputation to answer Matt, however you can easily parse this array by surrounding it with JSON.parse.
Example:
//assuming first argument (after the filename) will be an array
var argArray;
process.argv.forEach(function (arg, index, array)
{
switch (index)
{
case 2:
argArray = arg;
}
})
console.log(typeof(argArray), " var: ", argArray);
console.log(typeof(JSON.parse(argArray)), " var: ", argArray);
If you use this with an array argument written as such: "[\"test\", \"test\"]"
you should get the following output from this program:
string var: ["test", "test"]
object var: ["test", "test"]
As you can see the string-formatted-array parsed as a JSON-string gets converted to an object which can be treated like an array.