使用以下代码,我调用一个函数(“ firstFunction”),该函数生成一个Array并返回该数组。
async function doProcess() {
const checkState = await firstFunction();
console.log(checkState);
console.log(checkState.length);
return checkState;
}
使用console.log(checkState);
,我可以将整个阵列中的数据打印到控制台。
当我尝试访问值或数组数据时,例如console.log(checkState.length);
,我得到0
。我在这里做什么错了?
编辑[添加了“ firstFunction”]:
function firstFunction() {
var array = [];
var url3 = "/Home/CheckPrintService?printer=" + document.getElementById("printerName").value;
$.get(url3, null, function (data3) {
$("#msgPrinterName").html(data3);
var str = $("#msgPrinterName")[0].innerText.toString();
if (str.includes("ERROR CODE")) {
array.push(str);
}
//console.log($("#msgPrinterName")[0].innerText.toString());
});
var e = document.getElementById("ddlViewBy");
var deviceType = e.options[e.selectedIndex].text;
var url2 = "/Home/CheckIfValidIP?input=" + document.getElementById("ipAddress").value + "&type=" + deviceType;
$.get(url2, null, function (data2) {
$("#msgIPPort").html(data2);
var str = $("#msgIPPort")[0].innerText.toString();
if (str.includes("ERROR CODE")) {
array.push(str);
}
});
var url = "/Home/CheckPrinter?printer=" + document.getElementById("printerName").value;
$.get(url, null, function (data) {
$("#msgPrintService").html(data);
var str = $("#msgPrintService")[0].innerText.toString();
if (str.includes("ERROR CODE")) {
array.push(str);
}
});
return array;
}