Last active
September 14, 2017 22:23
-
-
Save javahaxxor/2ed28da0cf27c3c16bf83be1d2b94be5 to your computer and use it in GitHub Desktop.
Transform column data to objects
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function flip() { | |
var columns = [ | |
{ | |
"name": "address", | |
"rows": ['arow1', 'arow2', 'arow3', 'arow4', 'arow5'] | |
}, | |
{ | |
"name": "line1", | |
"rows": ['l1row1', 'l1row2', 'l1row3', 'l1row4', 'l1row5'] | |
}, | |
{ | |
"name": "line2", | |
"rows": ['l2row1', 'l2row2', 'l2row3', 'l2row4', 'l2row5'] | |
}, | |
{ | |
"name": "line3", | |
"rows": ['l3row1', 'l3row2', 'l3row3', 'l3row4', 'l3row5'] | |
}, | |
] | |
/* | |
[ | |
{ | |
address:arow1 | |
line1:lrow1 | |
line2:lrow2 | |
line3:lrow3 | |
}, | |
]*/ | |
var flipped = [columns[0].rows.length]; | |
for (var i=0; i<columns[0].rows.length; i++) { | |
flipped[i] = {}; | |
columns.forEach(col => { | |
flipped[i][col.name] = col.rows[i]; | |
console.log(flipped) | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment