So i have 2 arrays of objects , i want to get the name value from one and assign it to the label and value . This is what i am doing.
let newAreas = [{ label: '', value: '' }];
let areas = [{name: 'Haram', condition: true, counter: 5}, {name: 'Nasr City', condition: false, counter: 3}, {name: 'Faisl', condition: true, counter: 7}];
i want to get the each name and assign them to label and value so now i loop
areas.map(area => {
newAreas.map(val => {
val.label = area.name;
val.value = area.name;
});
});
console.log(newAreas);
but this only gets me the last value what am i doing wrong here ?
mapdoes not change the existing array but returns a new one.newAreasplays as an array with one object. Is that just there as a template for the objects you want? Nor is it clear what you need to have two keys with the same value.