Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

270
Views
how to get values for multidimensional array from user in node/javascript

getting values for a multidimensional array from users in C programming, we can use two for loops and scanf to get values.When I tried that in similar way in node javascript attempt was failed

I have tried something like this:

var readlineSync = require('readline-sync')
var arr = new Array();

console.log('enter aray values');

for (let i = 0; i < 6; i++){
    for (let j = 0; j < 6; j++){
       
 arr[i][j] = readlineSync.questionInt('')
   
 }

}

console.log(arr);

and I got an error saying :

arr[i][j] = readlineSync.questionInt('')
                  ^
TypeError: Cannot set properties of undefined (setting '0')
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

you can't set properties on undefined.

var readlineSync = require('readline-sync')
var arr = new Array();

console.log('enter aray values');

for (let i = 0; i < 6; i++) {
    for (let j = 0; j < 6; j++) {
        arr[i] = [];
        arr[i][j] = readlineSync.questionInt('')
    }
}

console.log(arr);
about 4 years ago · Juan Pablo Isaza Report

0

The error describes that arr[i] is undefined, which means that no properties can be set on it.

Each dimension of the multidimensional array should be created in each iteration of the loop:

for (let i = 0; i < 6; i++) {
    // 👇 initialize the dimension as an empty array
    arr[i] = new Array();
    for (let j = 0; j < 6; j++) {
        arr[i][j] = readlineSync.questionInt('')
    }
}
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!