function createTable(data, str){
var html ="";
for (i = 0; i < data.length; i++){
var color = ['#bad7ff','#a0f0f7'];
var arr = [];
color.forEach((el,i)=>{
arr[i] = '<tr id="trTOJ">' +
'<td bgcolor="'+color[i]+'">' + data[i].cod + '</td>' +
'<td bgcolor="'+color[i]+'">' + data[i].nr + '</td>' +
'<td bgcolor="'+color[i]+'">' + data[i].or + '</td>' +
'<td bgcolor="'+color[i]+'">' + data[i].np + '</td>' +
'<td bgcolor="'+color[i]+'">' + data[i].op + '</td>' +
'<td bgcolor="'+color[i]+'">' + data[i].is + '</td>' +
'<td bgcolor="'+color[i]+'">' + data[i].vr + '</td>';
});
if(str == 3){
if(data[i].st === 0 && data[i].is == 'текст1'){
html += arr[0] +
'<td class="btn btn-info btn-ioj" id="infoOrderJournal" data1="'+data[i].nr+'" data2="'+data[i].prim+'"\n\
>' +'Оформление'+ '</td>' +
'</tr>';
};
if(data[i].st === 1 && data[i].is == 'текст1'){
html += arr[1] +'<td class="btn btn-info btn-woj " id="warningOrderJournal" data1="'+data[i].nr+'" \n\
data2="'+data[i].prim+'">' +'Исполнение'+ '</td>' +
'</tr>';
};
}else if(str == 4){
if(data[i].st === 0 && data[i].is == 'текст2'){
html += arr[0] + '<td class="btn btn-info btn-ioj" id="infoOrderJournal" data1="'+data[i].nr+'" data2="'+data[i].prim+'"\n\
>' +'Оформление'+ '</td>' +
'</tr>';
};
if(data[i].st === 1 && data[i].is == 'текст2'){
html += arr[1] +'<td class="btn btn-info btn-woj " id="warningOrderJournal" data1="'+data[i].nr+'" \n\
data2="'+data[i].prim+'">' +'Исполнение'+ '</td>' +
'</tr>';
};
}else{
if(data[i].st === 0){
html += arr[0] + '<td class="btn btn-info btn-ioj" id="infoOrderJournal" data1="'+data[i].nr+'" data2="'+data[i].prim+'"\n\
>' +'Оформление'+ '</td>' +
'</tr>';
};
if(data[i].st === 1){
html += arr[1] + '<td class="btn btn-info btn-woj " id="warningOrderJournal" data1="'+data[i].nr+'" \n\
data2="'+data[i].prim+'">' +'Исполнение'+ '</td>' +
'</tr>';
};
};
};
$('#table').html(html);
}
можно и так, можно и более большие куски кода сохранить