Ver Mensaje Individual
  #2 (permalink)  
Antiguo 04/01/2008, 14:44
Avatar de Panino5001
Panino5001
Me alejo de Omelas
 
Fecha de Ingreso: mayo-2004
Ubicación: -34.637167,-58.462984
Mensajes: 5.148
Antigüedad: 20 años, 8 meses
Puntos: 834
Re: Funcion similiar a in_array pero en javascript.

Probá así:
Código PHP:
<script>
Array.
prototype.in_array=function(){
    for(var 
j in this){
        if(
this[j]==arguments[0]){
            return 
true;
        }
    }
    return 
false;    
}
colores=['azul','índigo','violeta'];
if(
colores.in_array('azul'))alert('pertenece');else alert('no pertenece');
if(
colores.in_array('verde'))alert('pertenece');else alert('no pertenece');

</script>