Tell me how to properly make such a function. I use javascript with the React framework
i am get from API this json array
[{
id: 0,
credit: {
id: 7
}
"another data"
}]
I want to have a result at the end, like this
[{
id: 0,
credit: {
id: 7,
bank: "Bank Name X" // This parameter must also be obtained from the API
}
"another data"
}]
i am try attach with this function
let fData;
let lData = [];
for (let i = 0; i < data.length; i++) {
fData = {
...data[i],
credit: {
bank: axios.get("http://localhost:8080/api/v1/products/credits/" + data[i].credit.id)
.then(function(result) {
return result.data.partner.name;
})
}
}
lData.push(fData);
}
console.log(lData);
This code returns. How to get Bank Name X
credit:
bank: Promise
__proto__: Promise
[[PromiseStatus]]: "resolved"
[[PromiseValue]]: "Bank Name X"