var str1='1 1\n1 1'; var str2=' 2 3 4\n5 6 7'; var str=str1+str2; console.log(str);
var str1='1 1\n1 1'; var str2=' 2 3 4\n5 6 7'; var table = []; [str1, str2].forEach(str => { str.split('\n').forEach((row, i) => { (table[i] || (table[i] = [])).push(row.trim()); }); }); console.log( table.map(cells => cells.join(' ')).join('\n') );