lodash faltteing
by Jorge Bustos Pereda
HTML
flattens the values in the nested arrays, keeping only thos in which incl is truish.
JavaScript
var a = [
{ nested: [
{ incl: 1, val:'a+' },
{ incl: 0, val:'b-' },
{ incl: 1, val:'c+' }
]
},
{ nested:[
{ incl: 0, val:'d-' },
{ incl: 1, val:'e+' },
{ incl: 1, val:'f+' }
]
}
];
console.log(a)
b = _.flatten(a, 'nested')
console.log(b)
c = _.flatten(a, function(val) {
return _.remove(val.nested, function(x) { return x.incl; } );
});
console.log(c)