Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

156
Views
How to filter JavaScript / JSON array
 function CountrySelection(ddlCountries, ddlCities, citiesData) {
    var selectedValue = ddlCountry.options[ddlCountry.selectedIndex].value;
    var ddlCities = document.getElementById(ddlCity);

    // Convert to array.
    var arr = JSON.parse(citiesData);
    // Loop throught the array.
    for (var i = 0; i < arr.length; i++)       
    console.log(arr[i]);
}

I have the above JavaScript function (i have removed code that is not necessary). The third parameter is a JSON string with the sample data below.

Sample JSON string:

[{"CityId":1,"CityName":"City 1","CityDescription":"City 1","Region":"XYZ","CountryId":01,"Active":true,"Order":1,"RegionId":"5192dab0-435c-464b-93ea-98c6a33928f5","Zone":"London"},
{"CityId":300,"CityName":"Test City","CityDescription":"Test City","Region":"Test City","CountryId":4,"Active":true,"Order":300,"RegionId":"b3114705-b522-4bd1-b7fd-5e07881e030c","Zone":"Kabiyo"},
{"CityId":301,"CityName":"City 12","CityDescription":"City 12","Region":"XCVFD","CountryId":4,"Active":true,"Order":301,"RegionId":"b3114705-b522-4bd1-b7fd-5e07881e030c","Zone":"Kabiyo"},
{"CityId":302,"CityName":"City 7","CityDescription":"City 7","Region":"City-7","CountryId":4,"Active":true,"Order":302,"RegionId":"b3114705-b522-4bd1-b7fd-5e07881e030c","Zone":"Kabiyo"},
{"CityId":1000000,"CityName":"Offices South","CityDescription":"Offices South","Region":"KPSD","CountryId":404,"Active":true,"Order":0,"RegionId":"fca4c3dc-a774-4dd4-a91b-7207868a22a6","Zone":"South"}]

How can i filter this JSON array based on CountryId = var selectedValue variable and then update my ddlCities asp.net dropdownlist with the filtered list.

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!