gpt4 book ai didi

javascript - 打印数组js仅显示对象

转载 作者:行者123 更新时间:2023-12-03 06:04:55 24 4
gpt4 key购买 nike

我需要读取大型文本文件并找到它们的长度并保存它们的数据。我想将它们的内容保存为数组。

当我调试程序时,我可以看到数组不为空,并且我可以看到想要的内容。

但是当我尝试打印数组时,我得到的只是 [object Object]。

代码

  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);

最佳答案

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

您正在获取 [object Object],因为您的数组包含另一个数组,并且 Arrays.prototype.toString() 不会深入到多维数组。

您应该迭代抛出 allFileGenesDetails 例如

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

或者您想将 allFileGenesDetails.push(fileGenesDetails) 替换为更多代码,将一个数组中的所有项目添加到另一个数组中。

关于javascript - 打印数组js仅显示对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39593270/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com