title: Adding object properties into a JSON object
body: <p>I have a JSON object in this format.</p>
  
  <pre><code>[
      {
          "name": "schoolname",
          "line id": "0",
          "time": "4-5",
          "minage": "15",
          "maxage": "35"
      },
      {
          "name": "studentname1",
          "line id": "1",
          "class": "A"
      },
      {
          "name": "studentname2",
          "line id": "2",
          "class": "B"
      }
  ]
  </code></pre>
  
  <p><strong>What I want to do</strong></p>
  
  <p>From a set of specified headers, get it from the <code>"line id" : "0"</code> and set it to the other items.</p>
  
  <p>For Example: 
  <code>headers = ["time", "minage", "maxage"]</code></p>
  
  <p>I get these from the <code>"line id" : "0"</code> and give it to others like this.</p>
  
  <pre><code>[
      {
          "name": "schoolname",
          "line id": "0",
          "time": "4-5",
          "minage": "15",
          "maxage": "35"
      },
      {
          "name": "studentname1",
          "line id": "1",
          "class": "A",
          "time": "4-5",
          "minage": "15",
          "maxage": "35"
      },
      {
          "name": "studentname2",
          "line id": "2",
          "class": "B",
          "time": "4-5",
          "minage": "15",
          "maxage": "35"
      }
  ]
  </code></pre>
  
  <p>and then remove the element with <code>"line id" : "0"</code>, like this:</p>
  
  <pre><code>[
      {
          "name": "studentname1",
          "line id": "1",
          "class": "A",
          "time": "4-5",
          "minage": "15",
          "maxage": "35"
      },
      {
          "name": "studentname2",
          "line id": "2",
          "class": "B",
          "time": "4-5",
          "minage": "15",
          "maxage": "35"
      }
  ]
  </code></pre>
  
  <p>It is said that the 1st element would be a <code>"line id" : "0"</code>.</p>
  
  <p><strong>What I've tried:</strong></p>
  
  <pre><code>var headers = ["time", "minage", "maxage"]
  var data = 
      [
          {
              "name": "schoolname",
              "line id": "0",
              "time": "4-5",
              "minage": "15",
              "maxage": "35"
          },
          {
              "name": "studentname1",
              "line id": "1",
              "class": "A"
          },
          {
              "name": "studentname2",
              "line id": "2",
              "class": "B"
          }
      ];
  
  for(var i = 1; i &lt; data.length; i++)//iterate over the data leaving the 1st line
  {
      for(var j = 0; j &lt; headers.length; j++)//add each header to the data lines
       {
          data[i][headers[j]] = data[0][headers[j]];
       }
  }
  data.splice(0,1);
  </code></pre>
  
  <p>Everything works fine and as intended. Is there a way to reduce the time-complexity of this and make it more efficient.</p>
  
  <blockquote>
    <p>This now has a time complexity of O(n * m).</p>
  </blockquote>
  
  <p>Is there a way around of adding these few objects to all the elements? As the key value pairs to be added for all the entries remain the same.</p>