I have an array like this:
pa: [{
id: 1,
sa: [ 1, 2, 3 ]
}, {
id: 2,
sa: [ 1, 2, 3 ]
}, {
id: 3,
}]
Some of the objects contain an sa
array and some don't. I want to create a new array that contains all the numbers of sa
in a new single array
I have tried this but it will add in multiple arrays
for (let i = 0; i < pa.length; i++) {
if (pa[i].sa!== undefined && pa[i]?.sa) {
f.push(p[i]?.sa?.map(a=> a.id));
}
}
i want the final array to be
newArray = [1,2,3,1,2,3]