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

192
Views
How to create a function for adding an object created by the same function into array?

I am creating html game where i generate platforms by manually adding them into the array platforms, therefore I created a function that will adding objects into that array. But it throws an error:

canvas.bundle.js:230 Uncaught TypeError: undefined is not iterable (cannot read property Symbol(Symbol.iterator))

let generation = ( object, array, image, y ) => {
  array = [... array, new object({
    x: LastPos, y, image
  })]
  LastPos = image.width + Math.floor(Math.random() * 1000)
}

generation(Platform,platforms,platformImage,470)
  • The reason to create that function is the attempt to make infinity game (runner)

the function execution will be in the loop

P.S object to be generating is the class:

class Platform {  
  constructor({x, y, image}) {
    this.position = {
      x, y
    }
    this.image = image
    this.width = image.width
    this.heigth = image.height

  }
  draw() {
    c.drawImage(this.image, this.position.x, this.position.y)
  }
}
about 4 years ago · Juan Pablo Isaza
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!