lodash remove code example
Example 1: lodash remove element from list
var colors = ["red","blue","green","green"];
var greens = _.remove(colors, function(c) {
return (c === "green");
});
Example 2: remove element from array lodash
var arr = [1, 2, 3, 3, 4, 5];
_.remove(arr, function(e) {
return e === 3;
});
console.log(arr);
Example 3: lodash remove not in array
var a = [
{id: 1, name: 'A'},
{id: 2, name: 'B'},
{id: 3, name: 'C'},
{id: 4, name: 'D'}
];
var removeItem = [1,2];
removeItem.forEach(function(id){
var itemIndex = a.findIndex(i => i.id == id);
a.splice(itemIndex,1);
});
console.log(a);
Example 4: lodash map
const _quote_filter = _.map(quote_state, (val, key) => { if (val) { return key }})console.log(_quote_filter)
Example 5: lodash map
_.each(markets, (obj, key) => { obj.symbol = key})console.log(markets)
Example 6: get lodash
var object = { 'a': [{ 'b': { 'c': 3 } }] }; _.get(object, 'a[0].b.c');