let mass1 = ["zn1", "zn2", "zn3"];
let mass2 = [
{t1: "aa", p1: "lot"},
{t1: "ab", p1: "kot"},
{t1: "ac", p1: "mot"}
]
let mass3 = [
{head: "zn1", t1: "aa", p1: "lot"},
{head: "zn2", t1: "ab", p1: "kot"},
{head: "zn3", t1: "ac", p1: "mot"},
]
let mass1 = ["zn1", "zn2", "zn3"]
let mass2 = [
{t1: "aa", p1: "lot"},
{t1: "ab", p1: "kot"},
{t1: "ac", p1: "mot"}
]
let mass3 = []
for (let i = 0; i < mass1.length; i++) {
mass3.push(
Object.assign(mass2[i], {head: mass1[i]})
)
}
reduce()
в копилку:const zip = (arr1, arr2) => arr1.reduce(
(acc, head, i) => (acc.push({ ...arr2[i], head }), acc),
[]
);
zip(mass1, mass2)
/* [
{ t1: "aa", p1: "lot", head: "zn1" },
{ t1: "ab", p1: "kot", head: "zn2" },
{ t1: "ac", p1: "mot", head: "zn3" },
] */
map()
тут больше подходит:mass1.map((head, i) => ({ head, ...mass2[i] }))