title: How to create a single object from key-value pairs objects in JavaScript?
body: <p>I have several objects and I want to create another one that will have keys from a particular array (<code>const props = []</code>), and values from those objects - if it only exists in those objects, but if not - I want to push <code>null</code> or some other fake values. </p>
  
  <p>My code:</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 props = ["name", "price", "qty", "category"]
  let len = props.length;
  
  const obj_1 = {
    name: "Product_1",
    price: 120,
    category: 'phone'
  }
  
  const obj_2 = {
    name: "Product_2",
    price: 7893,
    category: 'program_eq',
    qty: 5
  }
  
  const final_obj = {
    name: ["Product_1", "Product_2"],
    price: [120, 7893],
    category: ["phone", "program_eq"],
    qty: [null, 5]
  }</code></pre>
  </div>
  </div>
  </p>
  
  <p>I have spent lots of time with this problem and have some solution - but it gives me only the first object. 
  I am using lodash/map and it helps me to work with different type of collection.</p>
  
  <p>You can see my solution bellow: </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 final_obj = {};
      const props = ["name", "price", "qty", "category"];
      let len = props.length;
  
      const obj = {
        c1s6c156a1cascascas: {
          item: {
            name: "Product_1",
            price: 120,
            category: "phone"
          }
        },
        c454asc5515as41cas78: {
          item: {
            name: "Product_2",
            price: 7893,
            category: "program_eq",
            qty: 5
          }
        }
      };
  
      _.map(obj, (element, key) =&gt; {
        console.log(element.item);
        while (len) {
          let temp = props.shift();
          let tempData = [];
          if (element.item.hasOwnProperty([temp])) {
            tempData.push(element.item[temp]);
          } else {
            tempData.push("---");
          }
          final_obj[temp] = tempData;
          len--;
        }
      });
      console.log(final_obj); 
      
      //
      category:["phone"]
      name:["Product_1"],
      price:[120],
      qty:["---"],</code></pre>
  </div>
  </div>
  </p>