Last active
August 29, 2018 12:11
-
-
Save nijikokun/77d4cb6be20c4e740392 to your computer and use it in GitHub Desktop.
JSON to Markdown Table
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
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