So, my code goes like this:
await axios
.get(UrlGetOrderItems)
.then((response) => {
let arr = response.data.data.orders;
if (arr.length) {
getOrdersFromAPI = [];
arr.forEach((order) => {
let colName = order.order_id;
getOrdersFromAPI.push({
colName: {
voucher: order.voucher,
price: parseFloat(order.price),
shipping_fee: order.shipping_fee,
}
});
});
}
})
But results to the array being named as "colName"
{
colName: {
voucher: 50,
price: 1,
shipping_fee: 42,
subtotal: 1982,
}
}
How do I call the variable instead of the string 'colName'? I tried backticks (${colName}
) but results in an error. I'm using node js for this. Any ideas? Thanks in advance!