I am working on one Reactjs project- where i have cities and areas of each city ,in each city it may have more the 200 areas . Each area is having 3 attributes cityId,AreaID ,isAdded,
. And city is have one attribute cityId
.
Here i need to store Areas of each city in a separate array.How can i optimize this operation
export const getAreas = (cityID,allAreas) => {
try {
let areas = [];
if (allAreas) {
allAreas?.forEach((area) => {
if (area?.cityID === cityID) {
areas.push(area);
}
});
return areas;
}
} catch (error) {
console.log(error);
}
};