I want to filter this array of data in an array of states and cities. How can I achieve this using lodash or any other better way, rather than looping and supporting extra arrays.
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},
]
which the user clicks state
, a list of states appears.
{state: New York, count: 2},
{state: Texas, count: 1},
{state: Florida, count: 2},
{state: Chicago, count: 1},
When the user clicks a specific state, a list of cities
that state appears . E.g. when a user clicks New York State,
{id:1, name: Mike, city: philps}
{id:3, name: Jhon, city: market}