Sunday, 29 March 2009 11:38

I've been going through my $HOME looking for things to post, and came across this little snippet:

function inArray( needle, haystack )
{
  var i=0;
  var n=haystack.length
  for( i; i<n; i++ )
  {
    if( isArray( haystack[i] ) )
      if( inArray( needle, haystack[i] ) )
      {
        return true;
        break;
      }
    if( haystack[i] == needle )
    {
      return true;
      break;
    }
  }
  return false;
}
function isArray( testObject )
{
  return testObject && !(testObject.propertyIsEnumerable('length')) && typeof testObject === 'object' && typeof testObject.length === 'number';
}

Notice that "inArray" calls "isArray", so they are both required if using "inArray".

Last Updated on Thursday, 23 April 2009 14:19
 

Add your comment

Your name:
Comment:
  The word for verification. Lowercase letters only with no spaces.
Word verification:

The Joomla!® name is used under a limited license from Open Source Matters in the United States and other countries. Jeff Channell is not affiliated with or endorsed by Open Source Matters or the Joomla!® Project.

Santorum
Joomla Extensions