Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

272
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda