How to filter object depending on value of property

Let's suppose that we are working with the following object:

javascript
let object = {
    
    '🍈': {
        
        'type': 'healthy'
        
    },
    '🍉': {
    
        'type': 'healthy'
    
    },
    '🌭': {
    
        'type': 'unhealthy'
    
    },  
    '🥓': {
    
        'type': 'unhealthy'
    
    }
    
}

To filter healthy from unhealthy food (convenient if you are as hungry as I am right now):

javascript
// Transform object into array = [ ["🍈", {…}], ["🍉", {…}], ["🌭", {…}], ["🥓", {…}]]
let food = Object.entries(object);

// Filtering healthy foods
let healthyFoodArray = food.filter( ([emoji, object]) => object.type === 'healthy');

// Transforming array into object again
let healthyFoodObject = Object.fromEntries(healthyFoodArray);

Hi, I'm Erik, an engineer from Barcelona. If you like the post or have any comments, say hi.