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

246
Visualizações
Javascript Class, with one parameter passed to array;

I am trying to invoke a class with the code below:

class matchDetails {
        constructor(game, kit, player){
            this.game       = game;   // This remains static;
            this.kit        = color;  // This remains static;
            this.player     = new Array(player);
        }
        addMatchDetails(){
            // return "Coventry";
        }
    }
    
    ab = new matchDetails(23, 'red', 11);

On the constructor I want this.player to be an array where I can push additional values but I cannot fathom out how to code it.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

The simplest approach is keeping extending your contructor and add lines. You can initialize the array and push the value. See the example below:

class matchDetails {
    constructor(game, kit, player){
        this.game       = game;
        this.kit        = kit;
        this.player     = [];
        this.player.push(player)
    }
    addMatchDetails(){
        // return "Coventry";
    }
}

ab = new matchDetails(23, 'red', 'smith');

//pushing additional surnames
ab.player.push('jones');

console.log(ab)
//matchDetails { game: 23, kit: 'red', player: [ 'smith', 'jones' ] }

In addition, there is no "color" variable, so I changed it to "kit".

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