How to sort the array and display it to the console using ForEach and Filter, you first need to display all the last names, after that, the last names with the letter "F"? What am I doing wrong? 'use strict'; // https://reqres.in/api/users
fetch('https://reqres.in/api/users?per_page=12')
.then((response) => {
return response.json();
})
.then((body) => {
body?.data.forEach((item) => {
console.log(item.last_name);
})
const filtered = body?.data.filter((item) => {
return item.last_name === 'F';
console.log(filtered);
});
console.log(filtered);
});
You are not checking the first letter of the last name
fetch('https://reqres.in/api/users?per_page=12')
.then((response) => {
return response.json();
})
.then((body) => {
const filtered = body?.data.filter((item) => {
return item.last_name[0] === 'F';
});
console.log(filtered);
});