Create array of objects based on another array?
<p>I want to take an array like this:</p>

<pre><code>var food = [
    {
        name: 'strawberry',
        type: 'fruit',
        color: 'red',
        id: 3483
    },
    {
        name: 'apple',
        type: 'fruit',
        color: 'red',
        id: 3418
    },
    {
        name: 'banana',
        type: 'fruit',
        color: 'yellow',
        id: 3458
    },
    {
        name: 'brocolli',
        type: 'vegetable',
        color: 'green',
        id: 1458
    },
    {
        name: 'steak',
        type: 'meat',
        color: 'brown',
        id: 2458
    },
]
</code></pre>

<p>And I want to create something like this dynamically:</p>

<pre><code>var foodCategories = [
    {
        name: 'fruit',
        items: [
            {
                name: 'apple',
                type: 'fruit',
                color: 'red',
                id: 3418
            },
            {
                name: 'banana',
                type: 'fruit',
                color: 'yellow',
                id: 3458
            }
        ]
    },
    {
        name: 'vegetable',
        items: [
            {
                name: 'brocolli',
                type: 'vegetable',
                color: 'green',
                id: 1458
            },
        ]
    },
    {
        name: 'meat',
        items: [
            {
                name: 'steak',
                type: 'meat',
                color: 'brown',
                id: 2458
            }
        ]
    }
]
</code></pre>

<p>What's the best way to go about doing this?</p>
