I am developing a recipe website in which I am using an API to pull in ingredients and nutritional information. On my site, I am wanting to have a person search to add ingredients from this and only this list. I'm pretty green with javascript, so this likely is user error. What I've found so far is this:
const api_url = `https://reqres.in/api/users`;
const matchList = document.getElementById('results');
function getData(){
fetch(api_url).then(response =>{
return response.json();
}).then(data =>{
const html = data.data.map(user =>{
return `"${user.first_name}"`
}).join(',');
console.log(html);
});
};
let suggestions = [
"Taco",
];
I'm needing the "let suggestions = []" for a different piece of code, but I'm unable to capture the array that is found in the getData() function. Any thoughts on how to go about this?