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.

2
  • @ArunPJohny Thank you Commented Mar 20, 2016 at 5:03
  • 2
    "i try with rectangle=[]; but it didn't work." Where is rectangle defined ? Try wall = [] Commented Mar 20, 2016 at 5:03

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.