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

112
Visualizações
Add unlimited values into objects from textbox in JavaScript

Can you please show me a simple code which add unlimited values into JavaScript objects. I don't want single view "Toyota, 2014". I want show lists value after I add value from textbox.

 class Car {
      constructor(name, year) {
        this.name = name;
        this.year = year;
      }
    }

At code below, this is single value to add, but I need add many value doesn't matter, how many of number I want to add.

const myCar = new Car("Toyota", 2014); 

I expect to view many different values like

Toyota, 2014
Opel, 2018
Volkswagen, 2021
and many mores
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

It sounds like you want an array of Car objects:

const cars = [];

Then adding a Car is:

cars.push(new Car(make, year));
// Or some people do, which also works:
cars[cars.length] = new Car(make, year);

...where make and year come from the text boxes.

When you want to list them all, you'll use some kind of loop (the exact kinds depends on how you're listing them). My answer here shows the various ways you can loop through arrays.

More about arrays on MDN.

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