Ver Mensaje Individual
  #6 (permalink)  
Antiguo 14/06/2014, 21:13
Avatar de Italico76
Italico76
 
Fecha de Ingreso: abril-2007
Mensajes: 3.303
Antigüedad: 17 años, 1 mes
Puntos: 292
Respuesta: Como seleccionar un arreglo con condiciones

Te va a tocar recorrer de alguna forma el arreglo sea directa o indirectamente...... pero es imposible a priori saber en que posicion esta ese name:

Código Javascript:
Ver original
  1. <script>
  2.     var Players = new Array;
  3.    
  4.     Players.push({
  5.     width: 20,
  6.     height: 50,
  7.     posX: 33,
  8.     posY: 12,
  9.     direction: 's',
  10.     name: 'Maria',
  11. });
  12.  
  13.     Players.push({
  14.     width: 20,
  15.     height: 50,
  16.     posX: 33,
  17.     posY: 12,
  18.     direction: 's',
  19.     name: 'Pablo',
  20. });
  21.  
  22.  
  23.     Players.push({
  24.     width: 20,
  25.     height: 50,
  26.     posX: 33,
  27.     posY: 12,
  28.     direction: 's',
  29.     name: 'Juan',
  30. });
  31.  
  32.     aguja = 'Pablo'; // a buscar
  33.  
  34.     for (ix in Players)
  35.         if (Players[ix].name==aguja)
  36.             console.log('Encontrado '+aguja+' en posicion '+ix);
  37.    
  38. </script>

Imprime:

Cita:
Encontrado Pablo en posicion 1
__________________
Salu2!