У меня есть массив ниже, и у каждого элемента есть другой массив с именем FunctionalityChildren, мне нужно найти уникальный объект, который содержит свойство ActionFull , равное переменной, например, '/ budget / alloc' или '/ budget'
let bigArray = [
{
"FunctionalityID": 114,
"Name": "General Register",
"Action": "/general-register",
"Icon": "settings_input_composite",
"System_ID": 21,
"FunctionalityFather_ID": null,
"Active": 1,
"Priority": 1,
"FunctionalityChildren": [
{
"FunctionalityID": 115,
"Name": "Supplier",
"Action": "/supplier",
"Icon": "perm_contact_calendar",
"System_ID": 21,
"FunctionalityFather_ID": 114,
"Active": 1,
"Priority": 1,
"ProfileFunctionalities": [
{
"ProfileFunctionalityID": 1251,
"Profile_ID": 68,
"Functionality_ID": 115,
"CanInsert": true,
"CanUpdate": true,
"CanDelete": true
}
],
"ActionFull": "/general-register/supplier"
},
{
"FunctionalityID": 116,
"Name": "RPA",
"Action": "/rpa",
"Icon": "view_day",
"System_ID": 21,
"FunctionalityFather_ID": 114,
"Active": 1,
"Priority": 2,
"ProfileFunctionalities": [
{
"ProfileFunctionalityID": 1252,
"Profile_ID": 68,
"Functionality_ID": 116,
"CanInsert": true,
"CanUpdate": true,
"CanDelete": true
}
],
"ActionFull": "/general-register/rpa"
},
{
"FunctionalityID": 117,
"Name": "Cost Center",
"Action": "/cost-center",
"Icon": "home",
"System_ID": 21,
"FunctionalityFather_ID": 114,
"Active": 1,
"Priority": 3,
"ProfileFunctionalities": [
{
"ProfileFunctionalityID": 1253,
"Profile_ID": 68,
"Functionality_ID": 117,
"CanInsert": true,
"CanUpdate": true,
"CanDelete": true
}
],
"ActionFull": "/general-register/cost-center"
},
{
"FunctionalityID": 118,
"Name": "Departament",
"Action": "/departament",
"Icon": "donut_small",
"System_ID": 21,
"FunctionalityFather_ID": 114,
"Active": 1,
"Priority": 4,
"ProfileFunctionalities": [
{
"ProfileFunctionalityID": 1254,
"Profile_ID": 68,
"Functionality_ID": 118,
"CanInsert": true,
"CanUpdate": true,
"CanDelete": true
}
],
"ActionFull": "/general-register/departament"
},
{
"FunctionalityID": 119,
"Name": "Product Line",
"Action": "/product-line",
"Icon": "view_headline",
"System_ID": 21,
"FunctionalityFather_ID": 114,
"Active": 1,
"Priority": 5,
"ProfileFunctionalities": [
{
"ProfileFunctionalityID": 1255,
"Profile_ID": 68,
"Functionality_ID": 119,
"CanInsert": true,
"CanUpdate": true,
"CanDelete": true
}
],
"ActionFull": "/general-register/product-line"
},
{
"FunctionalityID": 120,
"Name": "Product",
"Action": "/product",
"Icon": "shopping_cart",
"System_ID": 21,
"FunctionalityFather_ID": 114,
"Active": 1,
"Priority": 6,
"ProfileFunctionalities": [
{
"ProfileFunctionalityID": 1256,
"Profile_ID": 68,
"Functionality_ID": 120,
"CanInsert": true,
"CanUpdate": true,
"CanDelete": true
}
],
"ActionFull": "/general-register/product"
}
],
"ProfileFunctionalities": [
{
"ProfileFunctionalityID": 1250,
"Profile_ID": 68,
"Functionality_ID": 114,
"CanInsert": false,
"CanUpdate": false,
"CanDelete": false
}
],
"ActionFull": "/general-register",
"HasFunctionalities": true,
"model": false
},
{
"FunctionalityID": 99,
"Name": "Budget Account",
"Action": "/budget-account",
"Icon": "monetization_on",
"System_ID": 21,
"FunctionalityFather_ID": null,
"Active": 1,
"Priority": 2,
"FunctionalityChildren": [
{
"FunctionalityID": 100,
"Name": "Sector",
"Action": "/sector",
"Icon": "account_balance",
"System_ID": 21,
"FunctionalityFather_ID": 99,
"Active": 1,
"Priority": 1,
"ProfileFunctionalities": [
{
"ProfileFunctionalityID": 1258,
"Profile_ID": 68,
"Functionality_ID": 100,
"CanInsert": true,
"CanUpdate": true,
"CanDelete": true
}
],
"ActionFull": "/budget-account/sector"
},
{
"FunctionalityID": 101,
"Name": "Group",
"Action": "/group",
"Icon": "group_work",
"System_ID": 21,
"FunctionalityFather_ID": 99,
"Active": 1,
"Priority": 2,
"ProfileFunctionalities": [
{
"ProfileFunctionalityID": 1259,
"Profile_ID": 68,
"Functionality_ID": 101,
"CanInsert": true,
"CanUpdate": true,
"CanDelete": true
}
],
"ActionFull": "/budget-account/group"
},
{
"FunctionalityID": 102,
"Name": "Account",
"Action": "/account",
"Icon": "attach_money",
"System_ID": 21,
"FunctionalityFather_ID": 99,
"Active": 1,
"Priority": 3,
"ProfileFunctionalities": [
{
"ProfileFunctionalityID": 1260,
"Profile_ID": 68,
"Functionality_ID": 102,
"CanInsert": true,
"CanUpdate": true,
"CanDelete": true
}
],
"ActionFull": "/budget-account/account"
},
{
"FunctionalityID": 103,
"Name": "Budget",
"Action": "/budget",
"Icon": "credit_card",
"System_ID": 21,
"FunctionalityFather_ID": 99,
"Active": 1,
"Priority": 4,
"ProfileFunctionalities": [
{
"ProfileFunctionalityID": 1261,
"Profile_ID": 68,
"Functionality_ID": 103,
"CanInsert": true,
"CanUpdate": true,
"CanDelete": true
}
],
"ActionFull": "/budget-account/budget"
}
],
"ProfileFunctionalities": [
{
"ProfileFunctionalityID": 1257,
"Profile_ID": 68,
"Functionality_ID": 99,
"CanInsert": false,
"CanUpdate": false,
"CanDelete": false
}
],
"ActionFull": "/budget-account",
"HasFunctionalities": true,
"model": false
},
{
"FunctionalityID": 105,
"Name": "Budget",
"Action": "/budget",
"Icon": "credit_card",
"System_ID": 21,
"FunctionalityFather_ID": null,
"Active": 1,
"Priority": 3,
"FunctionalityChildren": [
{
"FunctionalityID": 106,
"Name": "Allocation",
"Action": "/allocation",
"Icon": "note_add",
"System_ID": 21,
"FunctionalityFather_ID": 105,
"Active": 1,
"Priority": 1,
"ProfileFunctionalities": [
{
"ProfileFunctionalityID": 1272,
"Profile_ID": 68,
"Functionality_ID": 106,
"CanInsert": true,
"CanUpdate": true,
"CanDelete": true
}
],
"ActionFull": "/budget/allocation"
},
{
"FunctionalityID": 107,
"Name": "Copy",
"Action": "/copy",
"Icon": "content_copy",
"System_ID": 21,
"FunctionalityFather_ID": 105,
"Active": 1,
"Priority": 2,
"ProfileFunctionalities": [
{
"ProfileFunctionalityID": 1273,
"Profile_ID": 68,
"Functionality_ID": 107,
"CanInsert": true,
"CanUpdate": true,
"CanDelete": true
}
],
"ActionFull": "/budget/copy"
},
{
"FunctionalityID": 108,
"Name": "In And Out",
"Action": "/in-and-out",
"Icon": "swap_vertical_circle",
"System_ID": 21,
"FunctionalityFather_ID": 105,
"Active": 1,
"Priority": 3,
"ProfileFunctionalities": [
{
"ProfileFunctionalityID": 1274,
"Profile_ID": 68,
"Functionality_ID": 108,
"CanInsert": true,
"CanUpdate": true,
"CanDelete": true
}
],
"ActionFull": "/budget/in-and-out"
},
{
"FunctionalityID": 109,
"Name": "Account Accounting",
"Action": "/account-accounting",
"Icon": "assignment",
"System_ID": 21,
"FunctionalityFather_ID": 105,
"Active": 1,
"Priority": 4,
"ProfileFunctionalities": [
{
"ProfileFunctionalityID": 1275,
"Profile_ID": 68,
"Functionality_ID": 109,
"CanInsert": true,
"CanUpdate": true,
"CanDelete": true
}
],
"ActionFull": "/budget/account-accounting"
},
{
"FunctionalityID": 110,
"Name": "Event",
"Action": "/eventos",
"Icon": "shopping_cart",
"System_ID": 21,
"FunctionalityFather_ID": 105,
"Active": 1,
"Priority": 5,
"ProfileFunctionalities": [
{
"ProfileFunctionalityID": 1276,
"Profile_ID": 68,
"Functionality_ID": 110,
"CanInsert": true,
"CanUpdate": true,
"CanDelete": true
}
],
"ActionFull": "/budget/eventos"
},
{
"FunctionalityID": 111,
"Name": "Copy Counter",
"Action": "/copy-counter",
"Icon": "swap_vertical_circle",
"System_ID": 21,
"FunctionalityFather_ID": 105,
"Active": 1,
"Priority": 6,
"ProfileFunctionalities": [
{
"ProfileFunctionalityID": 1277,
"Profile_ID": 68,
"Functionality_ID": 111,
"CanInsert": true,
"CanUpdate": true,
"CanDelete": true
}
],
"ActionFull": "/budget/copy-counter"
}
],
"ProfileFunctionalities": [
{
"ProfileFunctionalityID": 1271,
"Profile_ID": 68,
"Functionality_ID": 105,
"CanInsert": false,
"CanUpdate": false,
"CanDelete": false
}
],
"ActionFull": "/budget",
"HasFunctionalities": false,
"model": false
},
{
"FunctionalityID": 112,
"Name": "Config",
"Action": "/config",
"Icon": "build",
"System_ID": 21,
"FunctionalityFather_ID": null,
"Active": 1,
"Priority": 4,
"FunctionalityChildren": [
{
"FunctionalityID": 113,
"Name": "Control Year Month",
"Action": "/control-year-month",
"Icon": "date_range",
"System_ID": 21,
"FunctionalityFather_ID": 112,
"Active": 1,
"Priority": 1,
"ProfileFunctionalities": [
{
"ProfileFunctionalityID": 1263,
"Profile_ID": 68,
"Functionality_ID": 113,
"CanInsert": true,
"CanUpdate": true,
"CanDelete": true
}
],
"ActionFull": "/config/control-year-month"
}
],
"ProfileFunctionalities": [
{
"ProfileFunctionalityID": 1262,
"Profile_ID": 68,
"Functionality_ID": 112,
"CanInsert": false,
"CanUpdate": false,
"CanDelete": false
}
],
"ActionFull": "/config",
"HasFunctionalities": true,
"model": false
},
{
"FunctionalityID": 121,
"Name": "Report",
"Action": "/report",
"Icon": "picture_as_pdf",
"System_ID": 21,
"FunctionalityFather_ID": null,
"Active": 1,
"Priority": 5,
"FunctionalityChildren": [
{
"FunctionalityID": 122,
"Name": "Report 1",
"Action": "/report-um",
"Icon": "picture_as_pdf",
"System_ID": 21,
"FunctionalityFather_ID": 121,
"Active": 1,
"Priority": 1,
"ProfileFunctionalities": [
{
"ProfileFunctionalityID": 1265,
"Profile_ID": 68,
"Functionality_ID": 122,
"CanInsert": true,
"CanUpdate": true,
"CanDelete": true
}
],
"ActionFull": "/report/report-um"
},
{
"FunctionalityID": 123,
"Name": "Report 2",
"Action": "/report-dois",
"Icon": "picture_as_pdf",
"System_ID": 21,
"FunctionalityFather_ID": 121,
"Active": 1,
"Priority": 2,
"ProfileFunctionalities": [
{
"ProfileFunctionalityID": 1266,
"Profile_ID": 68,
"Functionality_ID": 123,
"CanInsert": true,
"CanUpdate": true,
"CanDelete": true
}
],
"ActionFull": "/report/report-dois"
},
{
"FunctionalityID": 124,
"Name": "Report 3",
"Action": "/report-tres",
"Icon": "picture_as_pdf",
"System_ID": 21,
"FunctionalityFather_ID": 121,
"Active": 1,
"Priority": 3,
"ProfileFunctionalities": [
{
"ProfileFunctionalityID": 1267,
"Profile_ID": 68,
"Functionality_ID": 124,
"CanInsert": true,
"CanUpdate": true,
"CanDelete": true
}
],
"ActionFull": "/report/report-tres"
}
],
"ProfileFunctionalities": [
{
"ProfileFunctionalityID": 1264,
"Profile_ID": 68,
"Functionality_ID": 121,
"CanInsert": false,
"CanUpdate": false,
"CanDelete": false
}
],
"ActionFull": "/report",
"HasFunctionalities": true,
"model": false
},
{
"FunctionalityID": 125,
"Name": "Profile",
"Action": "/profile",
"Icon": "person",
"System_ID": 21,
"FunctionalityFather_ID": null,
"Active": 1,
"Priority": 6,
"FunctionalityChildren": [
{
"FunctionalityID": 126,
"Name": "New",
"Action": "/new",
"Icon": "plus_one",
"System_ID": 21,
"FunctionalityFather_ID": 125,
"Active": 1,
"Priority": 1,
"ProfileFunctionalities": [
{
"ProfileFunctionalityID": 1269,
"Profile_ID": 68,
"Functionality_ID": 126,
"CanInsert": true,
"CanUpdate": true,
"CanDelete": true
}
],
"ActionFull": "/profile/new"
},
{
"FunctionalityID": 127,
"Name": "List",
"Action": "/list",
"Icon": "view_list",
"System_ID": 21,
"FunctionalityFather_ID": 125,
"Active": 1,
"Priority": 2,
"ProfileFunctionalities": [
{
"ProfileFunctionalityID": 1270,
"Profile_ID": 68,
"Functionality_ID": 127,
"CanInsert": true,
"CanUpdate": true,
"CanDelete": true
}
],
"ActionFull": "/profile/list"
}
],
"ProfileFunctionalities": [
{
"ProfileFunctionalityID": 1268,
"Profile_ID": 68,
"Functionality_ID": 125,
"CanInsert": false,
"CanUpdate": false,
"CanDelete": false
}
],
"ActionFull": "/profile",
"HasFunctionalities": true,
"model": false
}
]
Приведенный выше код работает для меня, но я думаю, что существует еще один код, более сахарный, и я хочу изучить его:
let all = bigArray.reduce((prev, next) => {
return prev.concat(next.FunctionalityChildren)
}, [])
bigArray.reduce((prev, next) => all.push(next), [])
let desired1 = '/budget'
let desired2 = '/budget/allocation'
let element1 = all.find(e=>e.ActionFull === desired1) // return the object that contains ActionFull = '/budget' (can be father)
let element2 = all.find(e=>e.ActionFull === desired2) // return the object that contains ActionFull = '/budget/allocation' (can be child)
console.log(element1)
console.log(element2)
Обратите внимание, как я показал выше, это может бытьотец или ребенок.