javascript - Convert array of string to array of object using es6 or lodash -
i have array of string want turn array of object.
array = ['a', 'b', 'c'];
i want generate
array= [ {'name': 'a', 'ischecked': false, 'availibility': 0 }, {'name': 'b', 'ischecked': false, 'availibility': 0 }, {'name': 'b', 'ischecked': false, 'availibility': 0 } ];
i tried below , still returning originalarray!
array.map((name) => ({ name, ischecked: false, availability: 0 }));
how this?
you can use map
this:
array= ['a', 'b', 'c']; let newarr = array.map(item => { return { 'name': item, 'ischecked': false, 'availibility': 0 } }) console.log(newarr);
Comments
Post a Comment