Javascript Object Creation - Create Many Objects
<p>I am parsing an excel file, that has 7 columns and over 300k rows.</p>

<p>I need to create objects (Nodejs side) and make a bulk insert in the database.</p>

<p>I am wondering what would be the best way to create large amounts of objects for this purpose.</p>

<p>I have come up with three approaches, and not sure which one would be the nest in terms of speed and memory:</p>

<p>First:</p>

<pre><code>var bulkObjects = [];
worksheet.eachRow({includeEmpty: true}, function (row, rowNumber) {
    var currentObject = createRowObject(row.values);    
    bulkObjects.push(currentObject);
});

function createRowObject(row) {    

    return {
        Row1: row[1],
        Row2: row[2],
        Row3: row[3],
        Row4: row[4],
        Row5: row[5],
        Row6: row[6]
     }
}
</code></pre>

<p>Second:</p>

<pre><code>var bulkObjects = [];
worksheet.eachRow({includeEmpty: true}, function (row, rowNumber) {
    var currentObject = **new** createRowObject(row.values);    
    bulkObjects.push(currentObject);
});

function createRowObject(row) { 

    this.Row1: row[1],
    this.Row2: row[2],
    this.Row3: row[3],
    this.Row4: row[4],
    this.Row5: row[5],
    this.Row6: row[6]    
}
</code></pre>

<p>Third:</p>

<pre><code>var bulkObjects = [];
worksheet.eachRow({includeEmpty: true}, function (row, rowNumber) {
    var currentObject = createRowObject(row.values);
    bulkObjects.push(currentObject);
});

function createRowObject(row) {

    var o = new Object();
    o["Row1"] = row[1];
    o["Row2"] = row[2];
    o["Row3"] = row[3];
    o["Row4"] = row[4];
    o["Row5"] = row[5];
    o["Row6"] = row[6];

    return o;
}
</code></pre>

<p>Which one would be the best to create large amount of objects. Is there a another approach? </p>