/* For every row of data in data, generates an object that contains the data. Names of object fields are defined in keys. Arguments: - data: JavaScript 2d array - keys: Array of Strings that define the property names for the objects to create Source: https://gist.github.com/crstamps2/3111817 */ function getObjects(data, keys) { var objects = []; //Array to be returned for (var i = 0; i < data.length; ++i) { //For each row var object = {}; for (var j = 0; j < data[i].length; ++j) { //For each cell in the row var cellData = data[i][j]; object[keys[j]] = cellData; } objects.push(object); } return objects; }
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter