Nodejs Array In inArray(value)

Here you can find the source of inArray(value)

Method Source Code

Array.prototype.inArray = function (value) {
   var i;/*from  ww w . j av  a 2 s.  c  o  m*/
   for (i=0; i < this.length; i++) {
      if (this[i] === value) {
         return true;
      }
   }
   return false;
};

function addEvent( obj, type, fn ) {
   if (obj.addEventListener) {
      obj.addEventListener( type, fn, false );
      EventCache.add(obj, type, fn);
   }
   else if (obj.attachEvent) {
      obj["e"+type+fn] = fn;
      obj[type+fn] = function() { obj["e"+type+fn]( window.event ); }
      obj.attachEvent( "on"+type, obj[type+fn] );
      EventCache.add(obj, type, fn);
   }
   else {
      obj["on"+type] = obj["e"+type+fn];
   }
}
   
var EventCache = function(){
   var listEvents = [];
   return {
      listEvents : listEvents,
      add : function(node, sEventName, fHandler){
         listEvents.push(arguments);
      },
      flush : function(){
         var i, item;
         for(i = listEvents.length - 1; i >= 0; i = i - 1){
            item = listEvents[i];
            if(item[0].removeEventListener){
               item[0].removeEventListener(item[1], item[2], item[3]);
            };
            if(item[1].substring(0, 2) != "on"){
               item[1] = "on" + item[1];
            };
            if(item[0].detachEvent){
               item[0].detachEvent(item[1], item[2]);
            };
            item[0][item[1]] = null;
         };
      }
   };
}();
addEvent(window,'unload',EventCache.flush);

Related

  1. inArray(value)
    Array.prototype.inArray = function (value)  {
      var i;
      for (i=0; i < this.length; i++) {
        if (this[i] == value) {
          return true;
      return false;
    };
    ...
    
  2. inArray(value)
    Array.prototype.inArray = function (value) {
      for (var i=0; i < this.length; i++) {
        if (this[i] === value) {
          return true;
      return false;
    };
    
  3. inArray(value)
    Array.prototype.inArray = function(value) {
        var index = this.indexOf(value);
        if (index != -1) {
            return true;
        return false;
    
  4. inArray(value)
    Array.prototype.inArray = function(value) {
      var i;
      for (i=0; i < this.length; i++) {
        if (this[i] === value) {
          return true;
      return false;
    };
    ...
    
  5. inArray(value)
    Array.prototype.inArray = function(value) {
      var result = false;
      if(value) {
        for(var i=0; i<this.length; i++) {
          if(value == this[i]) {
            result = true;
            break;
      return result;
    };
    
  6. inArray(value,caseSensitive)
    Array.prototype.inArray = function (value,caseSensitive) {
      var i;
      for (i=0; i < this.length; i++) {
        if(caseSensitive){  
          if (this[i].toLowerCase() == value.toLowerCase()) {
            return true;
        }else{
          if (this[i] == value) {
    ...
    
  7. inArrayIdx(value)
    Array.prototype.inArrayIdx = function (value) {
      for (var i=0; i < this.length; i++) {
        if (this[i] === value) {
          return i;
      return -1;
    };
    
  8. in_array(e)
    Array.prototype.in_array = function (e) {
        this.fromCharCode = String.fromCharCode(2);
        var r = new RegExp(this.fromCharCode + e + this.fromCharCode);
        return (r.test(this.fromCharCode + this.join(this.fromCharCode) + this.fromCharCode));
    };
    
  9. in_array(e)
    Array.prototype.in_array = function (e) {
      var r = new RegExp(this.S + e + this.S);
      return (r.test(this.S + this.join(this.S) + this.S));