Skip to content

Instantly share code, notes, and snippets.

@Corbzilla
Created June 13, 2018 03:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Corbzilla/5dbede1923d640e5d0192e2a54994dff to your computer and use it in GitHub Desktop.
Save Corbzilla/5dbede1923d640e5d0192e2a54994dff to your computer and use it in GitHub Desktop.
let input = `NumberA, NumberB, String
1, 2, hello
2, 4, world
3, 6, !`
let splitInput = input.split('\n');
let labels = splitInput[0].split(',');
let ary = [];
for(let i = 1; i < splitInput.length; i++) {
let obj = {};
let objData = splitInput[i].split(',');
for(let j = 0; j < objData.length; j++) {
obj[labels[j]] = objData[j];
}
ary.push(obj);
}
console.log(ary);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment