I've got an object structured like this:
let fragment = {
"lcxsm-item-1-heading": "Romeo",
"lcxsm-item-1-heading-1-subheading": "Lima",
"lcxsm-item-1-heading-2-subheading": "Zero",
"lcxsm-item-1-heading-3-subheading": "France",
"lcxsm-item-1-heading-1-subheading-1-subitem": "Jupiter",
"lcxsm-item-1-heading-1-subheading-2-subitem": "Sunday",
"lcxsm-item-1-heading-1-subheading-3-subitem": "Match",
"lcxsm-item-2-heading": "email",
"lcxsm-item-2-heading-1-subheading": "password",
"lcxsm-item-2-heading-2-subheading": "user",
"lcxsm-item-2-heading-3-subheading": "Italia",
"lcxsm-item-3-heading": "you",
"lcxsm-item-3-heading-1-subheading": "Rome",
"lcxsm-item-3-heading-2-subheading": "Indiana",
"lcxsm-item-3-heading-3-subheading": "phone",
"lcxsm-item-3-heading-1-subheading-1-subitem": "number",
"lcxsm-item-3-heading-1-subheading-2-subitem": "mail",
"lcxsm-item-3-heading-1-subheading-3-subitem": "id"
}
My aim is to develop a function named "getObjectListWithPrefix" that will provide the following output.
[
{
"main-heading": "Romeo",
"subHeadings": [ "lima", "zero", "france" ],
"subItems": [ "Jupiter", "Sunday", "Match" ]
},
{
"main-heading": "email",
"subHeadings": [ "password", "user", "Italia" ]
},
{
"main-heading": "You",
"subHeadings": [ "Rome", "Indiana", "phone" ],
"subItems": [ "number", "mail", "id" ]
}
]
The specific function call I am using is
getObjectListWithPrefix("lcxsm-item-", fragment, "-heading")
. Can the object be iterated using just a prefix and suffix? There are cases where there are headings, subheadings, and sub-items for each subheading. Any assistance would be appreciated!