skip to Main Content

So I created a list of data and i need to be able to get the total number of data that has a status: ‘Open’ and display it in the console.log.

const approvals = [
  {
    id: 1,
    member: 'Charlie Lubin',
    payPeriod: 'Sun, Jan 15, 2023 - Sat, Jan 21, 2023',
    duration: '45:11:36',
    activity: '0.57',
    status: 'Open',
    submittedOn: '-',
  },
  {
    id: 2,
    member: 'Madelyn Baptista',
    payPeriod: 'Sun, Jan 15, 2023 - Sat, Jan 21, 2023',
    duration: '45:11:36',
    activity: '0.71',
    status: 'Open',
    submittedOn: '-',
  },
  {
    id: 3,
    member: 'Lincoln Arcand',
    payPeriod: 'Sun, Jan 15, 2023 - Sat, Jan 21, 2023',
    duration: '45:11:36',
    activity: '0.42',
    status: 'Approved',
    submittedOn: '-',
  },
{
    id: 4,
    member: 'Ryan Botosh',
    payPeriod: 'Sun, Jan 15, 2023 - Sat, Jan 21, 2023',
    duration: '-',
    activity: '-',
    status: 'Approved',
    submittedOn: '-',
  },
  {
    id: 5,
    member: 'Craig Workman',
    payPeriod: 'Sun, Jan 15, 2023 - Sat, Jan 21, 2023',
    duration: '45:11:36',
    activity: '0.65',
    status: 'Approved',
    submittedOn: '-',
  },
];

2

Answers


  1. const approvals = [
      {
        id: 1,
        member: 'Charlie Lubin',
        payPeriod: 'Sun, Jan 15, 2023 - Sat, Jan 21, 2023',
        duration: '45:11:36',
        activity: '0.57',
        status: 'Open',
        submittedOn: '-',
      },
      {
        id: 2,
        member: 'Madelyn Baptista',
        payPeriod: 'Sun, Jan 15, 2023 - Sat, Jan 21, 2023',
        duration: '45:11:36',
        activity: '0.71',
        status: 'Open',
        submittedOn: '-',
      },
      {
        id: 3,
        member: 'Lincoln Arcand',
        payPeriod: 'Sun, Jan 15, 2023 - Sat, Jan 21, 2023',
        duration: '45:11:36',
        activity: '0.42',
        status: 'Approved',
        submittedOn: '-',
      },
    {
        id: 4,
        member: 'Ryan Botosh',
        payPeriod: 'Sun, Jan 15, 2023 - Sat, Jan 21, 2023',
        duration: '-',
        activity: '-',
        status: 'Approved',
        submittedOn: '-',
      },
      {
        id: 5,
        member: 'Craig Workman',
        payPeriod: 'Sun, Jan 15, 2023 - Sat, Jan 21, 2023',
        duration: '45:11:36',
        activity: '0.65',
        status: 'Approved',
        submittedOn: '-',
      },
    ];
    
    console.log(approvals.filter(a => a.status === 'Open').length)
    Login or Signup to reply.
  2. Using the filter method, you can filter your list to return a new list that has only members that pass the specified check.

    console.log(approvals.filter((approval) => approval.status === 'Open'))
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search