So I have a very basic game and I need a "Restart" button to work instead of refreshing the game to restart the game. When I click the button I want to remove everything and then load the main function again, however the objects are not removed.
The objects:
myObstacles.push(new component(10, height, "green", x, 0));
myObstacles.push(new component(10, x - height - gap, "green", x, height + gap));
The code I've tried to use to remove the components:
myObstacles.clear();
delete myObstacles[i];
delete myObstacles();
What actually happens is that I restart everything except the components so they keep on duplicating instead of being removed and then generated again once the main function is started.
Other topics related to this didn't help me get a working result. Your help is truly appreciated!