我有對象的數組,有型的fruit
/vegetable
:lodash - 將對象移動到數組中的第一位?
對於一個類型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'}
];
這裏是我的嘗試小提琴: https://jsfiddle.net/zg6js8af/
我怎樣才能類型vegetable
是數組中的第一個項目,無論其當前索引的?
工程就像一個魅力,謝謝:) – Wonka