I seen many questions including this from 3 hours and still finding solution please help. Actually I am trying to map in an js file which return an array of object of array of object,
Structure of DataSet : country[{name:value, states: [{name:value},{....},...]}, {......}, ....]
and get an Array of States Name
Please tell me what is wrong in this code Thanks in advance.
const allCountryArray = require('../../data/allCountryArray.js');
const countrySelect = document.querySelector('#country');
const stateSelect = document.querySelector('#state');
const citySelect = document.querySelector('#city');
let countrySelectionValue;
let statesGot;
countrySelect.addEventListener('change', checkCountry);
function checkCountry(e){
countrySelectionValue = e.target.value;
if(!countrySelectionValue) return;
statesGot = allCountryArray.map(country => {
if(country.name == countrySelectionValue){
return country.states.map(state => state.name);
}
})
console.log(statesGot);
}
Remember I want to achive this with map else with loop I did this below
for(let country of allCountryArray){
if(country.name == countrySelectionValue){
statesGot = country.states.map(state => state.name);
}
}