0

How do i sort array of given objects by value of city:

const arr = [
{
name: "Prague - train station", value: 1041041, city: "Prague"
},
{
name: "Brno - bus station", value: 104411041, city: "Brno"
},
{
name: "Prague - bus station", value: 104411041, city: "Prague"
},
{
name: "Brno - train station", value: 44411041, city: "Brno"
},
]

so result will be sorted by city:

const sortedArr = [
{
name: "Prague - train station", value: 1041041, city: "Prague"
},
{
name: "Prague - bus station", value: 104411041, city: "Prague"
},
{
name: "Brno - bus station", value: 104411041, city: "Brno"
},
{
name: "Brno - train station", value: 44411041, city: "Brno"
},
]

Thanks you!

I am fetching a stations array which contains about 1000+ objects and after i filter them based on searchValueInput, i need to sort them by value of City. So stations in city will be close to each other.

0 Answers0