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

195
Visualizações
How can I get multiple elements from an array?
const studentName = [];

function AddNewMember(){
    for(var i=0; i<4 ; i++){
        var num1 = document.getElementById("vorodi").value;
        studentName.push(num1);
    }
}

I have an input from which I want to receive five names. You can't do this with this code. What is the solution to this problem?

about 4 years ago · Juan Pablo Isaza
3 Respostas
Responde à pergunta

0

you can use this solution

let num1 = document.getElementById("vorodi");
function AddNewMember(){
        let name = num1.value;
        studentName.push(name);
        num1.value = "";
        console.log(studentName);
    }

about 4 years ago · Juan Pablo Isaza Relatório

0

As I understand you want to take value of multiple inputs in (your case it is 4)

You can try below one "vorod"+i concat value of i with static text

const studentName = [];

function AddNewMember(){
alert("called")
    for(var i=0; i<4 ; i++){
        var num1 = document.getElementById("vorod"+i).value;
        studentName.push(num1);
    }
    console.log(studentName)
}
  <input type="text" id="vorod0"><br><br>
  <input type="text" id="vorod1"><br><br>
  <input type="text" id="vorod2"><br><br>
  <input type="text" id="vorod3"><br><br>
  <input type="button" value="Add Member" onclick="AddNewMember()">

about 4 years ago · Juan Pablo Isaza Relatório

0

I don't know exactly what you are trying to do but if you want to get mutiple elements from your document(assuming you are working with a html page) you can use the getElementsByClassName() or getElementsByTagName() functions but you have to put the tag or class in your html element.

about 4 years ago · Juan Pablo Isaza 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