title: javascript - return parent with only child that matches given search string in array of objects with nested object
body: <p>This is a follow up question from <a href="https://stackoverflow.com/questions/44550439/javascript-search-array-of-nested-objects-and-return-parent-if-value-is-found">my previous question</a>. From the answer I've received, I am able to search within nested object in an array of objects.</p>
  <p>Please find this <a href="https://jsfiddle.net/7eL7t0d1/7/" rel="nofollow noreferrer">fiddle for example</a>.</p>
  <pre><code>var data = [
  {
    'booking_name': 'gtec/1101822/lmikdy/ls-rmea/oss11',
    'asset_count': 2,
    'pdg': 'Invalid',
    'user_area': 'Invalid',
    'deployment_number': 'Invalid',
    'spoc': 'invalid',
    'release': 'Invalid',
    'start_date': '2017-06-12 00:00:00',
    'end_date': '2017-06-16 00:00:00',
    'asset_info': [
      {
        'bams_id': 'BAMS-1001423507',
        'hostname': 'GTVOSS11',
        'status': 10,
        'site_location': 'IEAT01 Tipperary',
        'rack_number': 'VIRTUAL RACK',
        'rack_u_position': 0,
        'manufacturer': 'EMC',
        'model': 'VM',
        
      },
      {
        'bams_id': 'BAMS-1001368001',
        'hostname': 'None',
        'status': 10,
        'site_location': 'IEAT01 Tipperary',
        'rack_number': 'VIRTUAL RACK',
        'rack_u_position': 0,
        'manufacturer': 'HP',
        'model': 'HP BL460C GEN8',
        
      }
  ],
  'full_name': 'Invalid (invalid)',
  'email_address': 'Invalid'
  },
  {
    'booking_name': 'gtec/1101822/lmikdy/ls-rmea/oss11',
    'asset_count': 2,
    'pdg': 'Invalid',
    'user_area': 'Invalid',
    'deployment_number': 'Invalid',
    'spoc': 'invalid',
    'release': 'Invalid',
    'start_date': '2017-06-12 00:00:00',
    'end_date': '2017-06-16 00:00:00',
    'asset_info': [
      {
        'bams_id': 'BAMS-1001423507',
        'hostname': 'GTVOSS11',
        'status': 10,
        'site_location': 'IEAT01 Tipperary',
        'rack_number': 'VIRTUAL RACK',
        'rack_u_position': 0,
        'manufacturer': 'EMC',
        'model': 'VM',
        
      }
  ],
  'full_name': 'Invalid (invalid)',
  'email_address': 'Invalid'
  }];
  </code></pre>
  <p>Here when I search for a string 'emc', the function returns two objects which is correct. But 'emc' as 'manufacturer' is in child object. And every child object does not satisfies this condition. The result I am looking for, for example 'emc', it should return 2 parent objects. First parent object should have only one child (the other child has 'hp' as manufacturer). Second parent object should have one child as it matches the search string.</p>
  <p>I tried to make a new object with search result but couldn't make it work.</p>
  <p><strong>How do I return parent object with only child that satisfies the given search string ?</strong></p>
  <p>Here is the <a href="https://chat.stackoverflow.com/rooms/146772/discussion-between-valay-desai-and-nina-scholz">chatlog on my previous question</a> which can help to understand the problem and requirement.</p>