Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

111
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!