Вот частично полный ответ, если кто-то хочет его sh закончить. Он не объединяет внешние свойства, и есть несколько вложенных круглых объектов
Input
let arr = [
{
"cat_id": 38,
"rm_id": 1,
"items": {
"Box": [
[
{
"parent_name": "Box",
"child_name": "Small",
"category_name": "Box",
"SP": {
"id": 203,
"type": 2,
"price": 15
},
"added": true
},
{
"parent_name": "Box",
"child_name": "Big",
"category_name": "Box",
"SP": {
"id": 203,
"type": 2,
"price": 15
},
"added": true
},
{
"parent_name": "Box",
"child_name": "Very Big",
"category_name": "Box",
"SP": {
"id": 203,
"type": 1,
"price": 15
},
"added": true
}
]
]
}
},
{
"cat_id": 37,
"rm_id": 1,
"items": {
"Box": [
[
{
"parent_name": "Box",
"child_name": "Small",
"category_name": "Box",
"SP": {
"id": 203,
"type": 1,
"price": 15
},
"added": true
},
{
"parent_name": "Box",
"child_name": "Big",
"category_name": "Box",
"SP": {
"id": 203,
"type": 2,
"price": 15
},
"added": true
},
{
"parent_name": "Box",
"child_name": "Very Big",
"category_name": "Box",
"SP": {
"id": 203,
"type": 1,
"price": 15
},
"added": true
}
]
],
"Sets": [
[
[
{
"parent_name": "Drawers",
"child_name": "Full",
"SP": {
"id": 172,
"type": 1,
"price": 20
}
},
{
"parent_name": "Drawers",
"child_name": "Queen",
"SP": {
"id": 174,
"type": 2,
"price": 20
},
"added": true
}
],
[
{
"parent_name": "Drawers",
"child_name": "Full",
"SP": {
"id": 172,
"type": 1,
"price": 20
}
},
{
"parent_name": "Drawers",
"child_name": "Queen",
"SP": {
"id": 174,
"type": 2,
"price": 20
},
"added": true
}
]
]
]
}
}
]
const isObject = function(obj){
return obj === Object(obj);
}
const myFunc = function(result, value){
if (Array.isArray(value)){
value.reduce(myFunc, result)
// value.filter(function(child) {
// return ! Array.isArray(child)
// })
}
if (isObject(value)) {
Object.values(value).reduce(myFunc, result)
Object.keys(value).forEach(child => {
if (child != "SP" && isObject(value[child])){
delete value[child]
}
})
}
//for(let i = 0; i<result.length; i++){
// result[i] = {...result[i], ...value}
//}
if (value.SP && value.added === true && value.SP.type === 2){
result.push(value)
}
return result
}
newArr = arr.reduce(myFunc, [])
Выход
[{
added: true,
category_name: "Box",
child_name: "Small",
parent_name: "Box",
SP: {
id: 203,
price: 15,
type: 2
}
}, {
added: true,
category_name: "Box",
child_name: "Big",
parent_name: "Box",
SP: {
id: 203,
price: 15,
type: 2
}
}, [circular object Object], [circular object Object], {
added: true,
category_name: "Box",
child_name: "Big",
parent_name: "Box",
SP: {
id: 203,
price: 15,
type: 2
}
}, [circular object Object], {
added: true,
child_name: "Queen",
parent_name: "Drawers",
SP: {
id: 174,
price: 20,
type: 2
}
}, [circular object Object], {
added: true,
child_name: "Queen",
parent_name: "Drawers",
SP: {
id: 174,
price: 20,
type: 2
}
}, [circular object Object]]