0

I am making a game and it has a 2D array which holds all of the terrain's data and when I click on a block I want it to delete from the array but I don't know how to splice a 2D array?

    IslandPieces.splice(IslandPieces, [x][0]);

This won't work?

1 Answers1

0

In my experience you'd want to set that part of the array to some "empty value" because it makes it much easier to map the contents of the array to canvas (otherwise each piece will need its own x and y coordinate).

If however you really think it'll be better to remove the piece try using 'splice' e.g.

var array = [2, 5, 9];
console.log(array)
var index = array.indexOf(5);
if (index > -1) {
  array.splice(index, 1);
}
// array = [2, 9]
console.log(array);

from: https://stackoverflow.com/a/5767335/8448005