For this kind of array:
let combinazioniMat = [
["Person1", "Person2", "Person3", "Person4", "Person6"],
["Person1", "Person2", "Person3", "Person5", "Person6"],
["Person1", "Person2", "Person3", "Person6", "Person5"],
]
I want for each array to add each of the element of another array:
let mediciPom = ["Person1", "Person4"]
I tried to do like this, but it doesn't work...
let combinazioniTemp =[]
for (let combN=0; combN<combinazioniMat.length;combN++){
for (let med of mediciPom){
combinazioniMat[combN].push(med);
combinazioniTemp.push(combinazioniMat[combN]);
combinazioniMat[combN].pop()
}}
THIS IS THE RESULT I WANT TO OBTAIN (UPDATED):
[
["Person1", "Person2", "Person3", "Person4", "Person6", "Person1" ],
["Person1", "Person2", "Person3", "Person4", "Person6", "Person4" ],
["Person1", "Person2", "Person3", "Person5", "Person6", "Person1" ],
["Person1", "Person2", "Person3", "Person5", "Person6", "Person4" ],
["Person1", "Person2", "Person3", "Person6", "Person5", "Person1" ],
["Person1", "Person2", "Person3", "Person6", "Person5", "Person4" ],
]
Moreover, I need the same function, but pushing the value only if not already present in the array To obtain this:
[
["Person1", "Person2", "Person3", "Person5", "Person6", "Person4" ],
["Person1", "Person2", "Person3", "Person6", "Person5", "Person4" ],
]
(Person1 will not be pushed because already present, and Person4 will be pushed only in the array in which it isn't)
Thanks and sorry if I was not clear before...
const targetArr = combinazioniMat.map(x => [...x, ...mediciPom]);<--- please try this and share your feedback. This will add all elements ofmediciPominto each array withincombinazioniMat.