Created
May 16, 2017 15:13
-
-
Save FreddyPoly/a7a64882731a2d7ce2b1a3412356bbec to your computer and use it in GitHub Desktop.
[JAVASCRIPT] Remove single element from array
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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