Created
April 12, 2019 11:09
-
-
Save stevemu/1421a263c952907645279b8cdf00fab0 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// convert a csv like array like this: | |
// const tourdates = [ | |
// ["date", "venue", "city"], | |
// ["jan 1", "paladium", "worcester"], | |
// ["jan 2", "irving", "nyc"], | |
// ["jan 3", "gramercy", "nyc"] | |
// ]; | |
// into objects, like this: | |
// objs = [ { date: "jan 1", venue: "paladium", city: "worcester" }, { date: "jan 2", venue: "irving", city: "nyc" }, ... ] | |
const tourdates = [ | |
["date", "venue", "city"], | |
["jan 1", "paladium", "worcester"], | |
["jan 2", "irving", "nyc"], | |
["jan 3", "gramercy", "nyc"] | |
]; | |
let titles = tourdates[0]; | |
let dates = tourdates.slice(1, tourdates.length); | |
let objs = dates.map((item) => { | |
let obj = {}; | |
for (let i = 0; i < titles.length; i++) { | |
obj[titles[i]] = item[i]; | |
} | |
return obj; | |
}) | |
console.log(objs); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment