0
class testClass {
    constructor(field) {
        this.field = field;
    }

    print() {
        console.log(this.field);
    }

    userInput1(data) {
        let Input = data.toString().trim();
        if (Input === 'r' || Input === 'R') {
            this.field[0][1] = '5';
            this.print();
        }
    }

    userInput() {
        process.stdin.on('data', this.userInput1);
    }
}

const testVar = new testClass([[1,2,3], [3,2,1], [4,5,6]]);
testVar.print();
testVar.userInput();

/I'm trying to get the user Input. If user providing the Input which I'm looking for then I'm trying to modify the elements in 2D array. I am working with a project which needs the above implementation to be a part of the entire code./

  • `process.stdin.on('data', this.userInput1.bind(this));` or `process.stdin.on('data', () => this.userInput1());` – Unmitigated Aug 10 '23 at 12:25

0 Answers0