Is there a way to return the result from fetch API with the same order req.body, the result return a random order
exports.bookData = async (req, res) => {
let inputList = req.body.isbns;
let bookData = [];
let price = [];
let shipping = [];
let headers = {
"Content-Type": "application/json",
Authorization: "6456_46446548498465",
};
let url = `https://api1/${inputList}`;
await fetch(url, { headers: headers })
.then((response) => {
if (response.ok) {
// calculate
return response.json();
}
})
.then((json) => {
if (json) {
bookData.push(json);
}
});
await fetch(
`https://api3.com/${inputList}/6465dc68-564h5466g-546f684g86/`
)
.then((response) => response.json())
.then((data) => {
console.log(data);
});
let result = {
bookData,
price,
shipping
};
return res.json(result);
};
Isbns : 2935689888, 2856989845, 1156464654
output:
bookData: [ { book: [Object] } ], { price: '$11.54', link: 'https://api/2856989845', },
bookData: [ { book: [Object] } ], { price: '$15.54', link: 'https://api/2935689888', },
bookData: [ { book: [Object] } ], { price: '$05.54', link: 'https://api/1156464654', },
**output: should be **
bookData: [ { book: [Object] } ], { price: '$15.54', link: 'https://api/2935689888', },
bookData: [ { book: [Object] } ], { price: '$11.54', link: 'https://api/2856989845', },
bookData: [ { book: [Object] } ], { price: '$05.54', link: 'https://api/1156464654', },