I have a function in which I pass an element of type string and I want to compare it with a property that each object that makes up the Array have. If it matches, it returns true and false.
function Carta(id, marca, puntos) {
this.id = id;
this.marca = marca;
this.puntos = puntos;
//GETTER
this.getId = function () {
return this.id;
}
this.getMarca = function () {
return this.marca;
}
this.getPuntos = function () {
return this.puntos;
}
}
lambo1 = new Carta("lambo1", "lamborghini", 25);
lambo2 = new Carta("lambo2", "lamborghini", 25);
bmw1 = new Carta("bmw1", "bmw", 25);
bmw2 = new Carta("bmw2", "bmw", 25);
volks1 = new Carta("volks1", "volkswagen", 25);
volks2 = new Carta("volks2", "volkswagen", 25);
nissan1 = new Carta("nissan1", "nissan", 25);
nissan2 = new Carta("nissan2", "nissan", 25);
function verificarCampo(elemento){
for (i=0; i<=baraja.length; i++) {
if(baraja[i]."objeto"."elementoObjeto"==elemento){
return true;
}
else{
return false;
}
}
}
But in the check "if (shuffles [i]." object "." elementObject "== element)" I do not know how to write it correctly since each object has a different name ...
Within each object its properties have the same names. Does anyone know how I could do it?