Skip to content

Instantly share code, notes, and snippets.

@parzibyte
Created July 29, 2019 22:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save parzibyte/5d8a2c470a7524aaad7cfa7096639cc1 to your computer and use it in GitHub Desktop.
Save parzibyte/5d8a2c470a7524aaad7cfa7096639cc1 to your computer and use it in GitHub Desktop.
let arreglo = [{
nombre: "Maggie",
tipo: "Perro",
edad: 3,
}, {
nombre: "Guayaba",
tipo: "Perro",
edad: 1,
}, {
nombre: "Snowball",
tipo: "Gato",
edad: 1,
},
];
// La búsqueda la pasamos a JSON
let busqueda = JSON.stringify({
nombre: "Snowball",
tipo: "Gato",
edad: 1,
});
console.log("Tenemos el arreglo: ", arreglo);
console.log("Buscando en donde el objeto sea igual a: ", busqueda);
let indice = arreglo.findIndex(mascota => JSON.stringify(mascota) === busqueda);
console.log("El elemento buscado está en el índice ", indice);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment