Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

247
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda