I have a nested array like this
const names= [[{name: "John"}, {name: "Mary"}],
[{name: "Paul"}, {name: "Peter"}]];
I would like inject country into the nested object
const country = {country :"USA"}
so that output looks like
[{name: "John", country : "USA"}, {etc} ,{etc} ]
The code idea have is something like this
const combined = names.map((map)=>
Object.assign({},
country,
/*something to extract name from nested array names*/),
{country}
)
Any suggestions how i could spread the object in the nested array to form the desired output?
If the code could be improved in other ways, please let me know as well
countrybe add to all array elements or just the first element in the nested array?