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

182
Vistas
How to creat array?

I have a project I am working, one part of the project requires it to use an array of objects. I understand what an array is and also understand how to create an object. I created a new object named student with properties of name, grade and student ID. each one of these object properties will be generated by user in input text fields. I have a button that I use to save every entry into an array but do not understand how to incorporate my student object into my array or not understanding properly what an array of objects is which is requirement for this project. I already had it set up to work with a parallel array and commented out lines to add my new student object and new student ID input field but now I am stuck. I researched it and am not getting information needed to complete this task or it is not very clear. This is what I have so far

<br>
<p><b>Student Name:</b></p>
<input id="inp" type="text"><br><br>

<p><b>Grade:</b></p>
<input id="inps" type="text"><br><br>

<p><b>Student ID:</b></p>
<input id="inpsid" type="text"><br><br>

<button type="button" onclick="enter()">Enter</button><br><br>

<button type="button" onclick="construct()">Constructor</button>
<p>Student Names List:</p>

<p id="iop"></p><br>
<p id="opo"></p><br>
<p id="hop"></p><br>
<p id="lop"></p><br>
<p id="aop"></p><br>
<p id="cop"></p><br>

<script>
  var studentArr = new Array();
  var scoreArr = new Array();

  function enter() {
    var student = {
      name: document.getElementById("inp").value,
      grade : "A",
      id : 001
    };

    // Just to test my object property is saving input correctly.
    document.getElementById("iop").innerHTML = student.name;

    studentArr.push(student.name);

    var stuval = "";

    for (i=0; i < studentArr.length; i++) {
      stuval = stuval + studentArr[i] + "<br/>";
    }
  }
</script>
about 4 years ago · Santiago Gelvez
1 Respuestas
Responde la pregunta

0

Change studentArr.push(student.name); to studentArr.push(student);. Right now you are only storing student names. You have created a student object with name, grade, and id - all bundled together. You can store the entire object in the array and read it later with studentArr[Array Index].property Where the property is either name, grade, or id.

about 4 years ago · Santiago Gelvez 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