I need to check if any one of the array element satisfies the given condition. but I get an error that "is is not defined".
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');
}
}
Change the following line:
if((tempfLength >length)&&(is(tempfArray[i]==parentName)))
{
}
to
if( (tempfLength >length) && (tempfArray[i] == parentName) )
{
// Do something here
}
Note:
&& or || ==the is() function is used like:
if((tempfLength >length)&&(parentName.is(tempfArray[i])))
{
}
Read the documentation:http://api.jquery.com/is/
Make sure that both parentName and tempfArray[i] are jquery objects
is is not definded.
This error says means that the function is() isn't available in the global context you are calling it.
As i understood the issue you can try this with 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');
}
}