jsonData = []
const getRandomPrice = () => Math.floor(Math.random() * (500 - 100 + 1)) + 100
const fetchChicken = async () => {
let res = await fetch(
'https://www.themealdb.com/api/json/v1/1/search.php?s=Chicken'
)
let data = await res.json()
data.meals.map((meal) => {
let obj = {
name: meal.strMeal,
image: meal.strMealThumb,
type: 'NVEG',
price: getRandomPrice()
}
chickenResults.push(obj)
})
return chickenResults
}
const fetchVeg = async () => {
let res = await fetch(
'https://www.themealdb.com/api/json/v1/1/search.php?s=Veg'
)
let data = await res.json()
data.meals.map((meal) => {
let obj = {
name: meal.strMeal,
image: meal.strMealThumb,
type: 'VEG',
price: getRandomPrice()
}
vegResults.push(obj)
})
return vegResults
}
let veg = fetchVeg()
let nonveg = fetchChicken()
jsonData = veg.push(nonveg)
console.log(jsonData)
How to append these two array which I got from fetch function
Async function returns Promise.
Обсуждают сегодня