0

I have stone = [];

stoneB.playerId = players[player.playerId].playerId

I push new elements into stone by stone.push(stoneB)

How would I go about removing all of the elements from stone that match stoneB.playerId for a given player?

vthree123
  • 15
  • 5

1 Answers1

1

.filter is probably your best bet here:

stone = stone.filter(d => d.playerId !== stoneB.playerId)

or more generally:

function remove(stone, playerId) {
  return stone.filter(d => d.playerId !== playerId);
}

stone = remove(stone, stoneB.playerId);
Wex
  • 15,539
  • 10
  • 64
  • 107