Necesito verificar si alguno de los elementos de la matriz cumple con la condición dada. pero me sale un error que dice "no is definido".
var tempfLength = tempfArray.length; for(var i=tempfLength-2;i> -1;i--){ alert(tempfArray[i]); if((tempfLength >length)&&(is(tempfArray[i]==parentName))){ $(this).hide('str'); } }Cambia la siguiente línea:
if((tempfLength >length)&&(is(tempfArray[i]==parentName))) { }a
if( (tempfLength >length) && (tempfArray[i] == parentName) ) { // Do something here }Nota:
&& o ||==la función is() se usa como:
if((tempfLength >length)&&(parentName.is(tempfArray[i]))) { }Lea la documentación: http://api.jquery.com/is/
Asegúrese de que parentName y tempfArray[i] sean objetos jquery
no está definido.
Este error dice que la función is() no está disponible en el contexto global al que la está llamando.
Como entendí el problema, puedes probar esto con Array.prototype.find() :
var $this = $(this); // <----make sure to cache it as in the array this doesn't belong to var tempfLength = tempfArray.length; //`----what you think. for(var i=tempfLength-2;i> -1;i--){ alert(tempfArray[i]); if((tempfLength >length)&&(tempfArray.find(function(item){item === parentName})))){ $this.hide('str'); } }