我想過濾這個數據數組到狀態和城市數組。我如何使用lodash或其他更好的方式來實現這一點,而不是循環和維護額外的數組。如何篩選反應本機中的對象數組?
data: [
{ id: 1, name: Mike, city: philps, state: New York},
{ id: 2, name: Steve, city: Square, state: Chicago},
{ id: 3, name: Jhon, city: market, state: New York},
{ id: 4, name: philps, city: booket, state: Texas},
{ id: 5, name: smith, city: brookfield, state: Florida},
{ id: 6, name: Broom, city: old street, state: Florida},
]
哪個用戶點擊state
,出現狀態列表。
{state: New York, count: 2},
{state: Texas, count: 1},
{state: Florida, count: 2},
{state: Chicago, count: 1},
當用戶點擊特定狀態時,出現該狀態的cities
列表。例如。當用戶點擊紐約州,
{id:1, name: Mike, city: philps}
{id:3, name: Jhon, city: market}
的可能的複製[什麼是GROUPBY對象的JavaScript的陣列上的最有效的方法?(https://stackoverflow.com/questions/14446511/what-is-the對於狀態計數,它的打印輸出數據數組是最有效的方法到對象上的一組javascript- – bennygenel