lodash array to object code example
Example 1: Lodash remove duplicates from array
var users = [
{id:1,name:'ted'},
{id:1,name:'ted'},
{id:1,name:'bob'},
{id:3,name:'sara'}
];
var uniqueUsersByID = _.uniqBy(users,'id');
var uniqueUsers = _.uniqWith(users, _.isEqual);
Example 2: lodash remove multiple items from array
var colors = ["red","blue","green","yellow"];
var removedColors = _.remove(colors, function(c) {
return (c === "green" || c === "yellow");
});
Example 3: how to convert array to object in lodash
var params = [
{ name: 'foo', input: 'bar' },
{ name: 'baz', input: 'zle' }
];
_.reduce(params , function(obj,param) {
obj[param.name] = param.input
return obj;
}, {});
Example 4: lodash map
_.each(markets, (obj, key) => { obj.symbol = key})console.log(markets)