My Opera is closing 3rd of March

Iniciando o Hoje

Começando a avançar

inArray, Remove - Funções JavaScript que sinto falta e tive que criar

Sempre que estou usando o JavaScript necessito das seguintes funções:

  • Remover uma variável do Array
    //Remove o elemento de acordo com a sua posição
    Array.prototype.remove = function(f, t) {
      var rest = this.slice((t || f) + 1 || this.length);
      this.length = f< 0 ? this.length + f: f;
      return this.push.apply(this, rest);
    };
    
    //Exemplo
     var meuArray = new Array("www.","flaviosilva",".",".net");
     meuArray.remove(2);
     for(i in meuArray)
      if(typeof meuArray[i] != 'function') //Responsável por não imprimir a função prototype(remove)
       document.write(meuArray[i]);
    
  • Verificar se uma variável já existe em um Array
    //Verifica se uma variável está no array
    Array.prototype.inArray = function(e){
     for(i in this)
      if(this[i]==e)
       return true;
     return false
    }
    
    //Exemplo
     var meuArray = new Array("www.","flaviosilva",".",".net");
     if(meuArray.inArray("flaviosilva")){
      document.writeln("Essa função foi retirada do blog: my.opera.com/fsdev");
     }else{
      document.writeln("Acesse também o site: www.flaviosilva.net"); 
     }
    

Controlando status de um video em Flash AS2Transformando em Horas, Minutos, Segundos e Milissegundos

Write a comment

New comments have been disabled for this post.

February 2014
S M T W T F S
January 2014March 2014
1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28