Skip to content

Instantly share code, notes, and snippets.

@nijikokun
Last active August 29, 2018 12:11
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nijikokun/77d4cb6be20c4e740392 to your computer and use it in GitHub Desktop.
Save nijikokun/77d4cb6be20c4e740392 to your computer and use it in GitHub Desktop.
JSON to Markdown Table
function jsonToMarkdownTable (array, columns) {
var cols = columns
? columns.split(",")
: Object.keys(array[0])
var table = ""
table += cols.join(" | ")
table += "\r\n"
table += cols.map(function () {
return '---'
}).join(' | ')
table += "\r\n"
array.forEach(function (item) {
table += Object.keys(item).map(function (key) {
return String(item[key])
}).join(" | ") + "\r\n"
})
return table
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment