我有對象的數組,我怎麼可以去搜索的所有對象,並根據屬性值排序對象
data = [
{key: 1, val: Mon, week: 0},
{key: 1, val: Wed, week: 0},
{key: 1, val: Mon, week: 1},
{key: 1, val: Mon, week: 1}
{key: 1, val: Mon, week: 2}
]
所需的輸出
week0Array = [{key: 1, val: Mon, week: 0},{key: 1, val: Wed, week: 0}]
week1Array = [{key: 1, val: Mon, week: 1}, {key: 1, val: Mon, week: 1} ]
week2Array = [{key: 1, val: Mon, week: 2}]
我試圖對它們進行分類在lodash中使用find不斷變得不明確
_.find(collection, [predicate=_.identity], [fromIndex=0])
剛剛'weekArray [0]','weekArray [1]'等怎麼樣呢?可以接受嗎?另外,'Mon'和'Wed'應該是字符串還是變量引用? –
嗯,它不會列出所有包含'week:0'的對象,例如 – Deano
我想你誤會了我。我問是否可以將所需的輸出調整爲數組而不是單獨的變量。 –