Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to get the total number of a data with a specific value in ReactJS?

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: '-',
  },
];

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading