I want to remove the spaces on both sides of the matrix (split with tab), why only the last line is executed and meets the requirements

function takeout(th) {

    var text2 = $("-sharpdata_matrix").val();//

    var allcon2 = text2.split("\n");//

    for (var i =0; i < allcon2.length; iPP) {//

        a = allcon2[i].split("\t");  //tab
       
            var ha=a.join("\t");//tab
            
        // console.log(ha);
         
            $(th).val($.trim(ha));//
    }
    return true;//
}



textarea  

< textarea onblur = "takeout (this);" id= "data_matrix" rows= "20" cols= "100"

        style=" height:218px;min-height:218px;width: 100%;margin-bottom: 20px;">ID    Zygote    2_cell    4_cell    8_cell    Morula    ICM

Pou5f1 1 6 0.6 0.1 16
Sox2 25 0.5 0.2 2 6651
Gata2 3 4 0.4 0.3 3 46
cMyc 4 3 0.3 0.4 4 36
Tet1 5 2 0.2 0.5 5 25
Tet3 6 1 0.1 0.6 6 1 < / textarea >


the last assignment overrides the previous one

var text = [];
for (var i =0; i < allcon2.length; iPP) {//

        a = allcon2[i].split('\t');  //tab
       
            var ha=a.join("\t");//tab
            
        // console.log(ha);
         
         
         //   $(th).val($.trim(ha));//
         //
         text.push($.trim(ha));
    }
    $(th).val(text.join('\n'))
Menu