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?
emp_ids, for instance). Assuming that's a typo, and you actually have an array of individual objects, there are a few duplicates on Stack Overflow. What research have you done and attempts made based on that research?_.flatMap(employees, 'course_data'))