How to add/push a new object to array upon mouse click in p5.js

for (let i = 0; i < balls.length; ++i) b.display(); is wrong! :scream:

Correct is for (let i = 0; i < balls.length; ++i) balls[i].display(); :nerd_face:

Other options: :sunglasses:

  • for (const b of balls) b.display();
  • balls.forEach(b => b.display());
1 Like