Last active
October 2, 2021 23:01
-
-
Save filiperdt/6b88dd535b0776ecc6edcf0efd10db1d to your computer and use it in GitHub Desktop.
Eliminar repetição de registros no JavaScript, em um Object array, no ES6+
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
// Eliminar os exclusivos idem uma matriz | |
arr.filter((v,i,a)=>a.findIndex(t=>(t.id === v.id))===i) | |
// Eliminar por várias propriedades ( placee name) | |
arr.filter((v,i,a)=>a.findIndex(t=>(t.place === v.place && t.name===v.name))===i) | |
// Eliminar por todas as propriedades (isso será lento para matrizes grandes) | |
arr.filter((v,i,a)=>a.findIndex(t=>(JSON.stringify(t) === JSON.stringify(v)))===i) | |
// Manter a última ocorrência | |
arr.slice().reverse().filter((v,i,a)=>a.findIndex(t=>(t.id === v.id))===i).reverse() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment