2-dimensional array to object

Let's suppose that we have this array:

javascript
let foodArray = [ ['🍈', 'Melon'], ['🍉', 'Watermelon'], ['🌭', 'Hot dog'], ['🥓', 'Bacon'] ];

We want to convert it into an object like that:

javascript
let foodObject = {
    
    '🍈': 'Melon',
    '🍉', 'Watermelon',
    '🌭', 'Hot dog',
    '🥓', 'Bacon'
    
}

We can use the Object.fromEntries() function to transform fruitArray into fruitObject:

javascript
let foodArray = [ ['🍈', 'Melon'], ['🍉', 'Watermelon'], ['🌭', 'Hot dog'], ['🥓', 'Bacon'] ];

let foodObject = Object.fromEntries(fruitArray);

That's it!

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