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

166
Views
Cant seem to push an object into an array

class Member {
    constructor(name, type, joindate, dob, points) {
        this.name = name;
        this.type = type;
        this.joindate = joindate;
        this.dob = dob;
        this.points = points;
    }
    ListInfo() {
        return this.name + "\n" + this.type + "\n" + this.joindate + "\n" + this.dob + "\n" + this.points + "\n";
    }
}

class MemberGroup {
    constrctor() {
        this.List = [];
    }
}

//Member Infos
var Members = new MemberGroup();
Members.List.push(new Member("Leonardo", "Gold", "1 Dec 2019", "1 Jan 1980", 1400));

I have checked and this code is definitely syntax valid, no idea where went wrong or what went wrong I just cant seem to push values into the array.

about 4 years ago · Santiago Gelvez
2 answers
Answer question

0

Change it to:

class Member {
    constructor(name, type, joindate, dob, points) {
        this.name = name;
        this.type = type;
        this.joindate = joindate;
        this.dob = dob;
        this.points = points;
    }
    ListInfo() {
        return this.name + "\n" + this.type + "\n" + this.joindate + "\n" + this.dob + "\n" + this.points + "\n";
    }
}

class MemberGroup {
    List = []
}

//Member Infos
var Members = new MemberGroup();
Members.List.push(new Member("Leonardo", "Gold", "1 Dec 2019", "1 Jan 1980", 1400));
console.log(Members.List);

You need to declare the var otherwise you can't find it.

about 4 years ago · Santiago Gelvez Report

0

It works, just fix constrctor to constructor in the MemberGroup class. I changed nothing else.

class Member {
    constructor(name, type, joindate, dob, points) {
        this.name = name;
        this.type = type;
        this.joindate = joindate;
        this.dob = dob;
        this.points = points;
    }
    ListInfo() {
        return this.name + "\n" + this.type + "\n" + this.joindate + "\n" + this.dob + "\n" + this.points + "\n";
    }
}

class MemberGroup {
    constructor() {  // Fix this typo
        this.List = [];
    }
}

//Member Infos
var Members = new MemberGroup();
Members.List.push(new Member("Leonardo", "Gold", "1 Dec 2019", "1 Jan 1980", 1400));
console.log(Members.List)

about 4 years ago · Santiago Gelvez 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!