如何使用 ForEach 和 Filter 对数组进行排序并将其显示到控制台?

How to sort the array and display it to the console using ForEach and Filter?

如何使用ForEach和Filter对数组进行排序并显示到控制台,首先需要显示所有姓氏,然后是字母“F”的姓氏?我究竟做错了什么? '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);
 });

您没有检查姓氏的第一个字母

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);
  });