I would like to sort out some data from a Fetch API JSON. Using Postman GET is fine, but when I use console.log() to print out the result, it has the [Array] printed out instead. Also, I cannot access the "foodNutrients" array in my code.
When I enter the url using Postman GET
"foodNutrients": [
{
"nutrientId": 1051,
"nutrientName": "Water",
"nutrientNumber": "255",
"unitName": "G",
"derivationCode": "A",
"derivationDescription": "Analytical",
"value": 0E-8
},
{
"nutrientId": 1003,
"nutrientName": "Protein",
"nutrientNumber": "203",
"unitName": "G",
"derivationCode": "A",
"derivationDescription": "Analytical",
"value": 24.40000000
},
]
But when I use Fetch and use console.log()
{
//some fields
foodNutrients: [Array]
},
my code
const dataFilter= (response) => {
console.log(response)
async function getData() {
fetch('https://api.nal.usda.gov/fdc/v1/foods/search?api_key=DEMO_KEY&query=0')
.then(response => response.json())
.then(response => dataFilter(response))
}
getData()
Thanks for the help :)
console.log(JSON.stringify(response, null, 2))?