I'm trying to create a filtered list of objects where each object in the list has both a label and value property.
First I use .pick to select the key/value pairs I want from the initial object, then I iterate over the 'picked' properties and push the key into an object property called label, and push the value of the property into a property called value. I then return the empty array.
function formatToInput(obj, list) {
    var empty = []
    _.forIn(_.pick(obj, list), (val, key) => {
        empty.push({
            label: _.startCase(key),
            value: val
        });
    });
    return empty;
}
// use like so
var test = {blue: 10, green: 5, yellow: 3, pink: 1};
var filter = ['green', 'yellow'];
var results = formatToInput(test, filter)
console.log(results);
// [{label: Green, value: 5}, {label: Yellow, value: 3}]
I'm trying to avoid having to manually create an array and pushing objects into it, but I couldn't find a solution (in Lodash) that would allow me to do this.


filterwhich are not intest? \$\endgroup\$