lodash – Move object to first place in array?

By Wonka

I have an array of objects, with type of fruit/vegetable:

For the one type vegetable I have, I want it to be the first item in the array, but I am not sure how to do so with lodash.

var items = [
    {'type': 'fruit', 'name': 'apple'},
    {'type': 'fruit', 'name': 'banana'},
    {'type': 'vegetable', 'name': 'brocolli'}, // how to make this first item
    {'type': 'fruit', 'name': 'cantaloupe'}

Here is a fiddle with my attempt:

How can I get type vegetable to be the first item in the array?

Source: Stack Overflow


Share it with your friends!

    Fatal error: Uncaught Exception: 12: REST API is deprecated for versions v2.1 and higher (12) thrown in /home/content/19/9652219/html/wp-content/plugins/seo-facebook-comments/facebook/base_facebook.php on line 1273