title: removing the properties based on another object
body: <p>Based on userAccessData Object i need to filter the properties so what ever properties inside 
  the fields are there they will be exist in the updatedValue, i am able to do it.</p>
  
  <p>also one more thing if the ouput is an empty object then there is no need to have that
  object want to remove that also </p>
  
  <p>i have tried the below code. its working but is there any better way and how should i remove 
  the empty object</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>const userAccessData = {
    forms: {
      student: [
        {
          studentDetails: ['read', 'create', 'update'],
        },
      ],
      class: [
        {
          classDetails: ['read', 'create', 'update'],
        },
        {
          classSecondaryDetails: ['read', 'create', 'update'],
        },
      ],
      school: [
        {
          schoolContact: ['read', 'create', 'update'],
        },
        {
          schoolAddress: ['read'],
        },
        {
          schoolBasicDetails: ['read', 'create'],
        },
        {
          schoolLocationDetails: ['read', 'create', 'update'],
        },
      ],
    },
    fields: {
      school: {
        schoolAddress: [
          {
            isAddress: ['read', 'update'],
          },
        ],
        schoolLocationDetails: [
          {
            status: ['read'],
          },
        ],
        schoolContact: [
          {
            contactAddress: ['read'],
          },
          {
            contactStatus: ['read', 'create'],
          },
        ],
      },
      student: {
        studentDetails: [
          {
            isAvailable: ['read'],
          },
        ],
      },
      class: {
        classDetails: [
          {
            classId: ['read', 'create', 'update'],
          },
        ],
      },
    },
  };
  
  let updatedValue = {
    values: {
      schoolContact: {},
      schoolLocationDetails: {
        status: '123',
      },
      schoolAddress: {
        isAddress: 'yes',
        status: 'no'
      },
    }
  };
  
  const updateDetailsWithAccess = (updatedData, accessListData, selectedSection) =&gt; {
    const accessForms = Object.keys(accessListData[selectedSection]);
    Object.keys(updatedData.values).forEach((o) =&gt; {
      if (accessForms.indexOf(o) === -1) {
        delete updatedData.values[o];
      }
    });
  
    Object.keys(updatedData.values).forEach((o) =&gt; {
      const accessFormsForFields = accessListData[selectedSection][o].map(field =&gt; Object.keys(field)[0])
      Object.keys(updatedData.values[o]).forEach((field) =&gt; {
        if (accessFormsForFields.indexOf(field) === -1) {
          delete updatedData.values[o][field];
        }
      });
    });
    return updatedData;
  
  };
  
  console.log(updateDetailsWithAccess(updatedValue, userAccessData.fields, 'school'))</code></pre>
  </div>
  </div>
  </p>
  
  <p><strong>expected output</strong></p>
  
  <pre><code>{
    "values": {
      "schoolLocationDetails": {
        "status": "123"
      },
      "schoolAddress": {
        "isAddress": "yes"
      }
    }
  }
  </code></pre>