There a re a couple of problems, some undefined keys in the loops and you are inserting a table into a table which is invalid HTML.
Code:
<table id="dce_table"></table>
<script type="text/javascript" data-author="Tony Partner">
$(document).on('ready pjax:scriptcomplete',function(){
function createDCE() {
var alternatives = ["Car","Bike","Train"];
var myVERSION = "2";
var myData = [
{ "Version":"1","Task":"1","Concept":"1","Att1":"Banane","Att2":"5€","Att3":"27,56","Att4":"$$$","Att5":"50°C"},
{ "Version":"1","Task":"1","Concept":"2","Att1":"Karotte","Att2":"10€","Att3":"58,87","Att4":"€€€","Att5":"165°F"},
{ "Version":"1","Task":"1","Concept":"3","Att1":"Banane + Karotte","Att2":"10€","Att3":"58,87","Att4":"€€€","Att5":"165°F"},
{ "Version":"2","Task":"1","Concept":"1","Att1":"Banane","Att2":"5€","Att3":"27,56","Att4":"$$$","Att5":"50°C"},
{ "Version":"2","Task":"1","Concept":"2","Att1":"Karotte","Att2":"10€","Att3":"58,87","Att4":"€€€","Att5":"165°F"},
{ "Version":"2","Task":"1","Concept":"3","Att1":"Banane + Karotte","Att2":"10€","Att3":"58,87","Att4":"€€€","Att5":"165°F"}
]
// Insert the header row
$('#dce_table').append('<thead><tr></tr></thead>');
// Create an array of the table headers
var col = [];
col.push("Option");
$.each(myData[0], function(key, val) {
if (key != "Version" && key != "Task" && key != "Concept") {
col.push(key);
}
});
col.push("Buttons here");
// Insert those headers
$.each(col, function(i, val) {
$('#dce_table thead tr:eq(0)').append('<th>'+val+'</th>')
});
// Insert the tbody element
$('#dce_table').append('<tbody></tbody>');
// Loop through the "myData" elements
var rowIndex = 0;
$.each(myData, function(i, rowData) {
// Only access those that match "myVERSION"
if (rowData["Version"] === myVERSION) {
// Insert a data row, including the first cell (row label?)
$('#dce_table tbody').append('<tr data-index="'+rowIndex+'"><td>'+alternatives[rowIndex]+'</td></tr>');
// Now insert the data cells
$.each(col, function(i, val) {
if(val in rowData) {
$('#dce_table tbody tr[data-index="'+rowIndex+'"]').append('<td>'+rowData[val]+'</td>');
}
});
rowIndex++;
}
});
}
createDCE();
});
</script>