Skip to content

Instantly share code, notes, and snippets.

@issa-tseng
Created March 24, 2014 07:51
Show Gist options
  • Save issa-tseng/9735910 to your computer and use it in GitHub Desktop.
Save issa-tseng/9735910 to your computer and use it in GitHub Desktop.
// iterate through each row of the dataset
for (var j = 0; j < parsedData.length; j++)
{
// create a js key/value hash object
var datum = {};
// fetch the row we're processing
var row = parsedData[j];
// iterate through each column of the row
for (var k = 0; k < fields.length; k++)
{
// read in our configuration and data for this column
var col = update.columns[k];
var field = row[k];
// perform replace operations if the configuration deems it so
if (col.replace != null)
field = field.replace(new RegExp(col.search, 'ig'), col.replace);
// perform date parsing and formatting if the configuration deems it so
if (col.moment != null)
field = moment(field, col.moment.in).format(col.moment.out);
// assume we should trim whitespace off the ends of our values
datum[col.name] = trim(field);
}
// save off this row's object
importData.push(datum);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment