2016-09-20 1 views
0

大きなテキストファイルを読み込み、その長さを見つけてデータを保存する必要があります。 コンテンツを配列として保存します。配列を印刷するjsはオブジェクトのみを表示します

プログラムをデバッグすると、配列が空でないことがわかり、必要なコンテンツが表示されます。

しかし、私が得るすべての配列を印刷しようとすると[オブジェクトオブジェクト]です。

コード

function ReadAllFileFromFileList(files, allFileGenesDetails) { 

    $("#my-progressbar-container").show(); 

    //Retrieve all the files from the FileList object 
    if (files) { 
     for (var i = 0, f; f = files[i]; i++) { 
     var r = new FileReader(); 


     r.onload = (function(f) { 
      var callBckFunction = RunVanDiagramAlgorithm_phase2; 
      return function(e) { 

      var fileGenesDetails = new Array(); 
      var geneQuery = new OrderedMap(); 

      var contents = e.target.result; 

      // Parse the data 
      var contentEachLine = contents.split("\n"); 
      for (var jj = 0; jj < contentEachLine.length; jj++) { 
       var lineContent = contentEachLine[jj].split("\t"); 

       // Verify there line structure is correct 
       if (lineContent.length >= 2) { 
       var geneDetails = { 
        Query: lineContent[0], 
        Subject: lineContent[1] 
       }; 

       if (!m_vennDiagramArguments.chkRemoveDuplicates_isChecked || !geneQuery.isContainKey(geneDetails.Query)) { 
        geneQuery.set(geneDetails.Query, geneDetails.Query); 

        fileGenesDetails.push(geneDetails); 
       } 
       } 

      } 
      // thats the array Im trying to print 

      allFileGenesDetails.push(fileGenesDetails); 
      document.getElementById("resultss").innerHTML = allFileGenesDetails.toString(); 

      FinishReadingFile(callBckFunction); 
      }; 
     })(f); 
+0

console.log(JSON.stringify(array))を試してください。 –

答えて

0

あなたは直接印刷方式で配列を使用しようとする場合は、「Objectオブジェクト」を取得しますあなたは

var stringToShow; 
allFileGenesDetails.forEach(function(itemInArray){ 
stringToShow+=itemInArray;// do something with the item here 
}); 
を使用してすべての値を反復処理することにより、いくつかの形式にそれを解析する必要があります

または代わりにあなただけの配列の内側にやるいただきました!そこに見たい場合はconsole.log(JSON.stringify(allFileGenesDetails));

+0

ありがとうございます!それは今では を働いています。私はcvsファイルとして配列を保存しようとしています iveはこのコードを使用しようとしました - http://jsfiddle.net/cr4gL29v/ そしてvarを(JSON.stringify(allFileGenesDetails))に切り替えてください。 それは動作しません...任意のアイデアなぜですか? – badbuda

+0

Array.toString()はあなたの配列が配列の配列であり、各配列アイテムを反復処理し、その上で.toString()メソッドを使用するためです –

1
var fileGenesDetails = new Array(); 
... 
allFileGenesDetails.push(fileGenesDetails); 

配列に別の配列が含まれていて、Arrays.prototype.toString()が多次元配列に深入りしないため、[object Object]が表示されています。

あなたは、このような

var str; 
allFileGenesDetails.forEach(function(array){ 
    str += array.toString() + ";"; // do some formatting here 
}); 

としてスローallFileGenesDetailsを繰り返す必要がありますまたはあなたが別のものに1つの配列からすべての項目を追加し、いくつかのより多くのコードにallFileGenesDetails.push(fileGenesDetails)を交換したいです。

関連する問題