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

245
Views
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 answers
Answer question

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