title: dynamically flatten nested array of objects javascript
body: <p>I'm trying to write a function that will accept a nested object array, and dynamically return the flattened result. <code>arrayProperties.filter()</code> is not returning an array of objects like I expect. </p>
  
  <pre><code>const data = [ 
      {
          parKeyA: "parValA",
          parKeyA1:
              {chiKeyA1: "chiValA1", chiKeyA2: "chiValA2"},
          parKeyA2: {chiKeyA3: "chiValA3"}
      },
      {
          parKeyB: "parValB",
          parKeyB1:
              {chiKeyB1:"chiValB1"}
      }
  ]
  
  flatData = flatNestedObjArray(data);
  console.log(flatData);
  
  function flatNestedObjArray(array) {
      let flatArray = array.map(element =&gt; {
          let arrayProperties = Object.entries(element);
          //filter not returning array of objects
          let nestedObjects = arrayProperties.filter(property =&gt; {
              const parentValue = property[1];
              if (typeof parentValue === "object" &amp;&amp; parentValue !== null) {
                  return parentValue;
              }
          });
          //nestedObjects should be array of objects
          let merged = nestedObjects.map(obj =&gt; element.concat(obj));
          return merged;
      });
      return flatArray;
  }
  </code></pre>
  
  <p>Expected Result:</p>
  
  <pre><code>const data = [ 
      {
          parKeyA: "parValA",
          chiKeyA1: "chiValA1",
          chiKeyA2: "chiValA2",
          chiKeyA2: "chiValA2"
      },
      {
          parKeyB: "parValB",
          chiKeyB1:"chiValB1"
      }
  ]
  </code></pre>