title: search for a particular key in a nested object in nodejs
body: <p>I have a nested object which looks like this :</p>
  <pre><code>let obj = {
  _id:{}
  person:{
      $search:{fname:true}
      _id:{},
      fname:{}
  },
  code:{},
  vnvEmpName:{}
  </code></pre>
  <p>}</p>
  <p>I have to search for a <strong>$search</strong> keyword in this and get the key which is inside it that is <strong>fname</strong> in this case, it can contain multiple keys as well and I have to retrieve all of it.</p>
  <p>I tried something like this :</p>
  <pre><code>function findById(obj, id) {                             
  
  var result;
  for (var p in obj) {
      if (obj.id === id) {
          return obj;
      } else {
          if (typeof obj[p] === 'object') {
              result = findById(obj[p], id);
              if (result) {
                  return result;
              }
          }
      }
  }
  return result;
  </code></pre>
  <p>}</p>
  <p>If the object is in this way :</p>
  <pre><code>let obj = {
  _id: {},
  person: {
      $search: {
          lname: true
      },
      _id: {},
      fname: {},
      something:{
          $search: {
              fname: true
          },
      }
  },
  code: {},
  $search: {
      mname: true
  },
  vnvEmpName: {}
  </code></pre>
  <p>}
  I want to retrieve all the attributes inside the $search of every block.</p>
  <p>but I don't know how to get the keys inside a particular key as I am so new to the javascript.</p>