How can I using lodash, with minimum code transform an array like this:
['Alfa','Betta','Gamma','Delta']
into:
[
{ squad: 'Alfa'},
{ squad: 'Betta'},
{ squad: 'Gamma'},
{ squad: 'Delta'},
]
In Lo-Dash (or Underscore):
_.map(['Alpha', 'Beta', 'Gamma', 'Delta'], function (squad) {
return { squad: squad };
});
In ES5:
['Alpha', 'Beta', 'Gamma', 'Delta'].map(function (squad) {
return { squad: squad };
});
In ES2015:
['Alpha', 'Beta', 'Gamma', 'Delta'].map(squad => ({ squad }));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With