Skip to content

Instantly share code, notes, and snippets.

@arturovt
Created June 6, 2019 23:24
Show Gist options
  • Save arturovt/3451a85e5577eea76ef377354cef019a to your computer and use it in GitHub Desktop.
Save arturovt/3451a85e5577eea76ef377354cef019a to your computer and use it in GitHub Desktop.
const userToRemoveIndex = this.users.indexOf(user);
this.users = this.users.filter((_, index) => {
return index !== userToRemoveIndex;
}); // BAD
this.users = [
...this.users.slice(0, userToRemoveIndex),
...this.users.slice(userToRemoveIndex + 1)
]; // BAD
const users = this.users.slice();
users.splice(userToRemoveIndex, 1);
this.users = users; // GOOD, we also change the reference
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment