So I have an object as follows:
var data = [
{
unmatchedLines: [], //possible big array ~700+ lines per entry
statusCode: 200,
title: "title",
message: "some message",
details: [],
objectDetails: []
},
{
//same object here
}
];
This array gets filled by service calls and then looped through for merging the output before sending this result back to the frontend.
function convertResultToOneCsvOutput(data) {
var outPutObject = {
unmatchedLines: [],
responses: []
};
for(var i = 0; i < data.length; i++) {
if(data[i].fileData) {
outPutObject.unmatchedLines = outPutObject.unmatchedLines.concat(data[i].fileData);
}
outPutObject.responses.push({
statusCode: data[i].statusCode,
title: data[i].title,
message: data[i].message,
details: data[i].details,
objectDetails: data[i].objectDetails,
})
}
return outPutObject;
};
Now I was first using delete
to get rid of the unmatchedLines
from the data
object so that, in stead of creating a whole new object and pushing this to the output I could do:
delete data[i].unmatchedLines;
outPutObject.responses.push(data[i]);
But then I read that delete
is very slow and stumbled upon a post stating that putting this to undefined
in stead of using delete
would be faster.
My question:
What is better to use in the end? delete
, setting to undefined
or creating a new object in itself like I am doing right now?