NodeJs Readline 值放入数组

NodeJs Readline value put into array

我正在使用 NodeJS readline 模块从文本文件中读取。它会将每一行返回到控制台,但是我希望它将返回的行添加到一个数组中。这是我到目前为止得到的代码,但它不起作用。我认为 rd.on 充当了一种 for 循环,但它看起来不像。如有任何帮助,我们将不胜感激!

    function getinfomation2(){
        var firstfile = [];
        var secondfile = [];
        var countvar = 0;
        readline = require('readline');

        var rd = readline.createInterface({
            input: fs.createReadStream('../FixtureProfiles/CFIP1.json'),
            output: process.stdout,
            terminal: false
        });

        // Add fixture details from file to array to later be called
        rd.on('line', function(line) {
            // if fails console.log(line) returns line in console
            firstfile(countvar) = line;
            console.log(firstfile(countvar))
            countvar = countvar +1;
        });
    }

firstfile(countvar) = line 不正确。

数组访问运算符是 [](参见 Array docs on MDN)。

另请查看 Array.push

firstfile.push(line)