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

117
Views
Create concatenated array based on property in an array of objects using lodash

I have some data that is an array of objects like so:


let employees = 
[
    {
        emp_id: "1",
        course_data : [
            {
                info: "info",
                for: "emp_id_1"
            },
            {
                info: "more_info",
                for: "emp_id_1 "
            },
            {
                info: "even_more_info",
                for: "emp_id_1 "
            },

        ],

        emp_id: "2",
        course_data : [
            {
                info: "info",
                for: "emp_id_2"
            },
            {
                info: "more_info",
                for: "emp_id_2 "
            },
            {
                info: "even_more_info",
                for: "emp_id_2 "
            },

        ],
    },
];

I want to create a conatenated array of objects from the course_data property all objects in the parent array have. In other words, I'd like to have my data in the following format so that I can run _.groupBy() on the it:

let concatenated_array = [
            {
                info: "info",
                for: "emp_id_1"
            },
            {
                info: "more_info",
                for: "emp_id_1 "
            },
            {
                info: "even_more_info",
                for: "emp_id_1 "
            },

            {
                info: "info",
                for: "emp_id_2"
            },
            {
                info: "more_info",
                for: "emp_id_2 "
            },
            {
                info: "even_more_info",
                for: "emp_id_2 "
            },

        ]

I'm thinking something like unionWith, but I'm not sure. Is this possible in lodash?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You can do it with only javascript tools, like that:

employees.map(empl => empl.course_data).flat()
about 4 years ago · Juan Pablo Isaza 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!