Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

270
Views
Filter data from Array of Objects contains Array of Objects

Here I have attendance details and I Want to filter every data that contains employees id:1.
for example: I have data like this:

const attendance = [
        {
            date: 1,
            employees: [
                {
                    id: 1,
                    name: 'mahadev',
                    status: 'p'
                },
                {
                    id: 2,
                    name: 'roshan',
                    status: 'p'
                },

            ]
        },
        {
            date: 2,
            employees: [
                {
                    id: 1,
                    name: 'mahadev',
                    status: 'a'
                },
                {
                    id: 2,
                    name: 'roshan',
                    status: 'p'
                },

            ]
        },
    ];

And I want Output like this:

[
  {
    date:1,
    employees: [
      {
        id:1,
        name:'mahadev',
        status:'p'
      }       
    ]  
  },
  {
    date:2,
    employees: [
      {
        id:1,
        name:'mahadev',
        status:'a'
      }       
    ]  
  },
]
about 4 years ago · Santiago Trujillo
2 answers
Answer question

0

Try using map and filter.

const attendance = [{
    date: 1,
    employees: [
      { id: 1, name: 'mahadev', status: 'p' },
      { id: 2, name: 'roshan', status: 'p' }
    ]
  },
  {
    date: 2,
    employees: [
      { id: 1, name: 'mahadev', status: 'a' },
      { id: 2, name: 'roshan', status: 'p' }
    ]
  },
];

const filtered = id =>
  attendance.map(a => {
    const employees = a.employees.filter(e => e.id === id);
    return { ...a, employees };
  });
  
console.log(filtered(1));

about 4 years ago · Santiago Trujillo Report

0

Using map() and filter()

const filtered = id =>
  attendance.map(a => {
    const employees = a.employees.filter(emp => emp.id === id);
    return { date:a.date, employees };
  });
console.log(filtered(1))
about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!