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

181
Views
Each time I push new data to the array of object, the name property becomes "undefined"

Below is the class in which I try to push new data to the array of objects

 static addCustomer(input) {
        // buyTicket
        let data = Model.readCustomer();
        let theaterId = Number(input[0]);
        let name = input[1];
        let gender = input[2];
        let seatNumber = input[3];
        let ticketType = input[4];
        let custId = 1;
        let theaterName = "xxi";
        let movie = "movie";
    
        if (data.length !== 0) {
          custId = data[data.length - 1].id + 1;
        }
    
        switch (theaterId) {
          case 1:
            theaterName = "Cinema 12";
            movie = "Codezilla";
            break;
          case 2:
            theaterName = "Bioskop IXX";
            movie = "The Journey to Center of OOP";
            break;
          case 3:
            theaterName = "Moviemaxx";
            movie = "Avatar The Legend of Callback";
            break;
          case 4:
            theaterName = "VGCinema";
            movie = "Git The Kungfu Master";
            break;
          case 5:
            theaterName = "Bioskop IXX";
            movie = "Json The Protector";
            break;
    
          default:
            break;
        }
    
        let newCustomer = new Customer(
          custId,
          name,
          gender,
          new Ticket(theaterName, ticketType, movie, seatNumber)
        );
    
        data.push(newCustomer)
        console.log(data)
      }

This is the console.log result, you notice that the name property of the previous data becomes "undefined" each time I try to push new data to the array.

screenshot

Below is my "Customer" class in which I import to the models.js file

class Customer {
  constructor(id, customerName, gender, ticket) {
    this.id = id;
    this.customerName = customerName;
    this.gender = gender;
    this.ticket = new Ticket(
      ticket.theaterName,
      ticket.type,
      ticket.movie,
      ticket.seatNumber
    );
  }
}

class Ticket {
  constructor(theaterName, type, movie, seatNumber) {
    this.theaterName = theaterName;
    this.type = type;
    this.movie = movie;
    this.seatNumber = seatNumber;
  }
}
about 4 years ago · Juan Pablo Isaza
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!