1

im working on a game(snake) with obstacles, when the user get their score to 5 I create more blocks as obstacles:

wall = new Array(),
wall.push(new Rectangle(30, 50, 10, 10));

is there a clear/empty option in js, to delete the rectangles that i insert in the array i try with

rectangle=[];

but it didn't work.

Dmitri Pavlutin
  • 18,122
  • 8
  • 37
  • 41
Pedro
  • 1,440
  • 2
  • 15
  • 36

1 Answers1

1

There are 2 options:

1) Modify the length property

var wall = new Array(),
wall.push(new Rectangle(30, 50, 10, 10));

wall.length = 0;

2) Use the splice() method

wall.splice(0);

Check this interesting article about the length property.

Dmitri Pavlutin
  • 18,122
  • 8
  • 37
  • 41