我需要使index_to_write變量在函數外部可見。我怎樣才能使這成為可能?const XlsxPopulate = require('xlsx-populate');let found = false;let i = 1;let index_to_write = 0;XlsxPopulate.fromFileAsync("todo-list.xlsx") .then(workBook => { while (i <= 10 && found === false){ const value = workBook.sheet("Do-Shopping").cell("A" + i.toString()).value(); if (value === undefined) { found = true; index_to_write = i.toString(); } i++; } });console.log("A " + index_to_write + " is the first one to be free of data");我嘗試return index_to_write;在下面添加index_to_write = i.toString();但它不能解決問題。目前,它顯示0,與初始化時一樣,但它應該打印4。如何修復它?非常感謝您!
無法讓變量在 Node js 的函數之外可見?
偶然的你
2024-01-18 16:23:54