I am trying to fetch some data from a remote API, filter it and later display it, when I console.log it I see that it is present, however, I can’t figure out how to save the data in a variable once fetched, how can I do it? Here is my attempt:
let newData = null
const fetchedData = fetch('https://jsonplaceholder.typicode.com/posts')
.then((response) => response.json())
.then((json) => newData(json));
const orderEmployees = newData.filter(employee => employee.jobTitle === 'Sales Representative');
const initialFilterState = { };
orderEmployees.forEach(employee => {
if(employee.fullName === 'Wait Peperell') {
initialFilterState[employee.id] = false;
} else {
initialFilterState[employee.id] = true;
}
});