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

168
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 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