<!DOCTYPE html>
<html>

  <head>
    <link rel="stylesheet" href="style.css">
    <script src="script.js"></script>
  </head>

  <body>
    <h3>Hello Plunker!</h3>
    please open browser console to see output.
    <pre id="output">
      
    </pre>
    <button onclick="getObj(0)">Get new object</button>
  </body>

</html>
// Code goes here

var output = {};
  var id = ["trans", "fund"]
  //on first call
  var obj1 = {
    country: "SG",
    trans: [{
      rate: 20,
      members: 100
    }]
  }
  //on second call
  var obj2 = {
    country: "TH",
    fund: [{
      rate: 20,
      members: 100
    }]
  }

  function getObj(selectedValue) {
    console.clear();
    console.log('id array: ', id);
    id.forEach(x => {
      let obj1Key = obj1[x];
      if (obj1Key) output[x] = obj1Key;

      let obj2Key = obj2[x];
      if (obj2Key) output[x] = obj2Key;
    })
    console.log('output object', output);
    console.log('JSON:', JSON.stringify(output));
  }
/* Styles go here */