M
M
MuradSky2021-09-10 10:57:48
React
MuradSky, 2021-09-10 10:57:48

I want to set up filtering, such an object, how can I do it in js?

Hello colleagues! I want to set up filtering of such an object. How can I do it?

[
  {
  "region": "Moscov",
  "cities": [
     {"name": "Moscov1"},
     {"name": "Moscov2"},
     {"name": "Moscov3"},
     {"name": "Moscov4"},
     {"name": "Moscov5"}
  ]
},
{
  "region": "Altay",
  "cities": [
     {"name": "Altay1"},
     {"name": "Altay2"},
     {"name": "Altay3"},
     {"name": "Altay4"},
     {"name": "Altay5"}
  ]
}
]


1. enter data into search -> if the string matches the name of the region, display a list of cities with the name of the region;
2. otherwise, if it does not match, then we search by the name of the city, if the name of the city coincides with the string, then we display this particular city with the name of its region;
3. Otherwise, we remove the list.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question