there are two arrays arr01 and arr02
now add a field from the arr01 array to the arr02. The problem now is that the resulting new array is always the last field of the arr01
let arr01 = [
{
"account" : "000000000000"
},
{
"account" : "111111111111"
},
{
"account" : "2222222222222"
}
];
let arr02 = [
{
"city" : ""
},
{
"city" : ""
},
{
"city" : ""
}
];
let newArr = [];
arr01.map((cur01,eq) => {
arr01.map((cur02,index) => {
cur02.account = cur01.account;
return newArr.push(cur);
})
})
final result:
newArr = [
{
"account" : "2222222222222",
"city" : ""
},
{
"account" : "2222222222222",
"city" : ""
},
{
"account" : "2222222222222",
"city" : ""
},
{
"account" : "2222222222222",
"city" : ""
},
{
"account" : "2222222222222",
"city" : ""
},
{
"account" : "2222222222222",
"city" : ""
},
{
"account" : "2222222222222",
"city" : ""
},
{
"account" : "2222222222222",
"city" : ""
},
{
"account" : "2222222222222",
"city" : ""
}
];
the result I want is:
newArr = [
{
"account" : "000000000000",
"city" : ""
},
{
"account" : "000000000000",
"city" : ""
},
{
"account" : "000000000000",
"city" : ""
},
{
"account" : "111111111111",
"city" : ""
},
{
"account" : "111111111111",
"city" : ""
},
{
"account" : "111111111111",
"city" : ""
},
{
"account" : "2222222222222",
"city" : ""
},
{
"account" : "2222222222222",
"city" : ""
},
{
"account" : "2222222222222",
"city" : ""
}
];