Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

190
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda