let object = [{
id: `01`, name: `fish`, type: `marine`,
}, {
id: `02`, name: `fish`, type: `fresh`,
}, {
id: `03`, name: `fish`, type: `tank`,
}, {
id: `04`, name: `animal`, type: `pet`,
}, {
id: `05`, name: `animal`, type: `wild`,
}, {
id: `06`, name: `animal`, type: `zoo`,
}, {
id: `07`, name: `food`, type: `veg`,
}, {
id: `08`, name: `food`, type: `non-veg`,
}]
let data = []
object.map((value) => {
data.push([value.name, value.type])
})
console.log(data)
I can fetch data outside the map function in first example but in second second example i can't fetch data
let object = [{
id: `01`, name: `fish`, type: `marine`,
}, {
id: `02`, name: `fish`, type: `fresh`,
}, {
id: `03`, name: `fish`, type: `tank`,
}, {
id: `04`, name: `animal`, type: `pet`,
}, {
id: `05`, name: `animal`, type: `wild`,
}, {
id: `06`, name: `animal`, type: `zoo`,
}, {
id: `07`, name: `food`, type: `veg`,
}, {
id: `08`, name: `food`, type: `non-veg`,
}]
let data=[];
let test;
object.map(async (value) => {
test = await getValue(value.name);
data.push([value.name,value.type,test]);
})
console.log(data);
As in first example i can easily fetch data outside the map function fut in second function I am getting blank array how can i fetch async await data outside map function
- where am i doing wrong i don't get it