Get the key using Object.values().map()

This is a banana:

jsx
const banana = {

    'emoji': '🍌',
    'kcal': 89,
    'fat': 0.3,
    'carbohydrate': 23,
    'protein': 1.1

}

To get the keys and values we can use Object.entries() instead of Object.values(), combined with the map() function:

jsx
Object.entries(banana).map( ([key, value]) => `I am a healthy banana and my ${key} is/are ${value}`);

By the way, bananas are delicious and they have only ~40 kcal more than apples. If you eat two apples, you will ingest more calories than eating a banana.

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