title: sorting an object elements by matching prefix
body: <p>I am having an object like the below one.</p>
  <pre><code>let fragment = {
      &quot;lcxsm-item-1-heading&quot;: &quot;Romeo&quot;,
      &quot;lcxsm-item-1-heading-1-subheading&quot;: &quot;Lima&quot;,
      &quot;lcxsm-item-1-heading-2-subheading&quot;: &quot;Zero&quot;,
      &quot;lcxsm-item-1-heading-3-subheading&quot;: &quot;France&quot;,
      &quot;lcxsm-item-1-heading-1-subheading-1-subitem&quot;: &quot;Jupiter&quot;,
      &quot;lcxsm-item-1-heading-1-subheading-2-subitem&quot;: &quot;Sunday&quot;,
      &quot;lcxsm-item-1-heading-1-subheading-3-subitem&quot;: &quot;Match&quot;,
  
      &quot;lcxsm-item-2-heading&quot;: &quot;email&quot;,
      &quot;lcxsm-item-2-heading-1-subheading&quot;: &quot;password&quot;,
      &quot;lcxsm-item-2-heading-2-subheading&quot;: &quot;user&quot;,
      &quot;lcxsm-item-2-heading-3-subheading&quot;: &quot;Italia&quot;,
  
      &quot;lcxsm-item-3-heading&quot;: &quot;you&quot;,
      &quot;lcxsm-item-3-heading-1-subheading&quot;: &quot;Rome&quot;,
      &quot;lcxsm-item-3-heading-2-subheading&quot;: &quot;Indiana&quot;,
      &quot;lcxsm-item-3-heading-3-subheading&quot;: &quot;phone&quot;,
      &quot;lcxsm-item-3-heading-1-subheading-1-subitem&quot;: &quot;number&quot;,
      &quot;lcxsm-item-3-heading-1-subheading-2-subitem&quot;: &quot;mail&quot;,
      &quot;lcxsm-item-3-heading-1-subheading-3-subitem&quot;: &quot;id&quot;
  }
  </code></pre>
  <p>I am trying to create a function called &quot;getObjectListWithPrefix&quot; which gives me an output like this.</p>
  <pre class="lang-json prettyprint-override"><code>[
    {
      &quot;main-heading&quot;: &quot;Romeo&quot;,
      &quot;subHeadings&quot;: [ &quot;lima&quot;, &quot;zero&quot;, &quot;france&quot; ],
      &quot;subItems&quot;: [ &quot;Jupiter&quot;, &quot;Sunday&quot;, &quot;Match&quot; ]
    },
    {
      &quot;main-heading&quot;: &quot;email&quot;,
      &quot;subHeadings&quot;: [ &quot;password&quot;, &quot;user&quot;, &quot;Italia&quot; ]
    },
    {
      &quot;main-heading&quot;: &quot;You&quot;,
      &quot;subHeadings&quot;: [ &quot;Rome&quot;, &quot;Indiana&quot;, &quot;phone&quot; ],
      &quot;subItems&quot;: [ &quot;number&quot;, &quot;mail&quot;, &quot;id&quot; ]
    }
  ]
  </code></pre>
  <p>I am using the function call
  <code>getObjectListWithPrefix(&quot;lcxsm-item-&quot;, fragment, &quot;-heading&quot;)</code>only. Is it possible to loop through the object just using a prefix and suffix? Sometimes there may be heading, subheading, and sub-items for each subheading. Can someone help me ??</p>