I am creating a cli app & I get an input from the user : print [{name:'joe', age:19}]
where arg = [{name:'joe', age:19}]
But when I do typeof arg
, it returns string
. I tried using json.parse
[throws error], slice(1,-1)
[removes outer array brackets & type remains string] and Array.from(arg)
[splits all the brackets & letters into different elements].
So how do I convert [{name:'joe', age:19}]
into type object array?
Code Snippet :
vorpal
.command('input <array>')
.action(function(args,cb) {
let array = args.array;
this.log(array); //returns [{name:'joe',age:19}]
this.log(typeof array); //returns string
cb();
});