Skip to content

Instantly share code, notes, and snippets.

@FreddyPoly
Created May 16, 2017 15:13
Show Gist options
  • Save FreddyPoly/a7a64882731a2d7ce2b1a3412356bbec to your computer and use it in GitHub Desktop.
Save FreddyPoly/a7a64882731a2d7ce2b1a3412356bbec to your computer and use it in GitHub Desktop.
[JAVASCRIPT] Remove single element from array
// On cherche l'index de l'élément à supprimer (ici un objet)
const index = array.indexOf(leg);
// In exécute la méthode slice si l'index n'est pas -1
// Le deuxième argument est le nombre d'éléments à supprimer
if (index !== -1) array.splice(index, 1);
// Solution à faible performance car la méthode 'slice' est très couteuse
// Si besoins de performances alors utiliser une autre structure de données qu'un Array
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment