Если вы имеете право на плоский массив, то, возможно, это для вас:
const arr = [
[
{
type: "some type1",
name: "some name"
},
{
type: "some type2",
name: "some name"
}
],
[
{
type: "some type3",
name: "some name"
},
{
type: "some type4",
name: "some name",
customAttr: "something custom"
}
],
[
{
type: "some type5",
name: "some name"
},
{
type: "some type6",
name: "some name"
},
customAttr= "something custom1"
]
];
const flatArray = (arr) => {
return arr.reduce(function (flat, toFlatten) {
return flat.concat(Array.isArray(toFlatten) ? flatArray(toFlatten) : toFlatten);
}, []);
}
const flattened = flatArray(arr);
const result = flattened.filter(fi => fi.type && fi.name ).map(f=> {
return {
type: f.type,
name: f.name
}
});
console.log(result);
ОБНОВЛЕНИЕ:
В случае избежания сплющивания массива, вы можете сделать следующее (будьте осторожны, он будет работать простодля двумерного массива):
const testArray = [
[
{
type: "some type1",
name: "some name"
},
{
type: "some type2",
name: "some name"
}
],
[
{
type: "some type3",
name: "some name"
},
{
type: "some type4",
name: "some name",
customAttr: "something custom"
}
],
[
{
type: "some type5",
name: "some name"
},
{
type: "some type6",
name: "some name"
},
customAttr= "something custom1"
]
];
const beautifyArray = (srcArray) => {
srcArray.forEach((el, i) => {
el = el.filter(fi=> fi.type && fi.name)
.map(a => { return { type: a.type, name: a.name}});
testArray[i] = el;
});
console.log(testArray);
}
beautifyArray(testArray)