我有一个对象数组,其中包含类型为fruit
/vegetable
两种。
对于类型为vegetable
的那个,我想让它成为数组中的第一项,但我不确定如何使用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'}
];
这里有我的fiddle尝试: https://jsfiddle.net/zg6js8af/
我怎样才能让类型为 vegetable
的项目成为数组的第一项,而不管它目前的索引是多少?