title: Angular 2 - Creating a CSV file from nested Array
body: <p>I am trying to create an object for csv file from the nested array which looks something like this -</p>
  
  <pre><code>[
    {
      "Name":obj.name,
      "Age": obj.age,
      "Class":obj.class
    }
  ]
  </code></pre>
  
  <p>I have generated this array using the code which looks something like -</p>
  
  <pre><code>let obj = originalObj.map(studentObj =&gt; {
     return {
       "Name":studentObj.name,
       "Age":studentObj.age,
       "class":studentObj.class
     }
  }
  </code></pre>
  
  <p>Now here the <code>obj.class</code> is an object of comma separated values i.e <code>maths,biology,physics</code>. The number of classes are not fixed and dynamic, what I mean is a person can have 2 classes or 3 or 4 or can have no class at all. The csv i want to generate should look something like this -</p>
  
  <pre><code>| Name | Age | Class     | Class     | Class      |
  |------|-----|-----------|-----------|------------|
  | abc  | 12  |           |           |            |
  | xyz  | 18  | Computers |           |            |
  | ijk  | 20  | Astronomy | Geography | Science    |
  </code></pre>
  
  <p>How do I transform the array object to generate the required object which can generate the csv like above? I would preferably not use any external npm library for this unless it is absolutely necessary.</p>
  
  <p>I did tried with the sample code provided below by @Mr. Ratnadeep and it works well if the number of classes are fixed, but in my case the first record don't have a class hence while converting into <code>csv</code> keys are not getting generated for the class at all. Need help to solve this challenge I am out of my depth.</p>