// Первый массив
const defaultTest = {
main: "first1",
references: [
{ something: "something1" },
{ something: "something2" },
]
}
// Второй массив
const systemTest = {
main: "first2",
references: [
{ something: "something11" },
{ something: "something22" },
]
}
// То что я хочу получить на выходе
const test = [
{ something: "something1", main: "first1", defaultTest: true },
{ something: "something2", main: "first1", defaultTest: true },
{ something: "something11", main: "first2", systemTest: true },
{ something: "something22", main: "first2", systemTest: true },
]
Object
.entries({ defaultTest, systemTest })
.flatMap(([ k, { references, ...n } ]) => references.map(m => ({
...m,
...n,
[k]: true,
})))
Object
.entries({ defaultTest, systemTest })
.map(([ k, v ]) => v.map(({ references, ...n }) => references.map(m => ({
...m,
...n,
[k]: true,
}))))
.flat(2)