Se ordenan según el elemento que se seleccione. Puede probar pinchando sobre la cabecera de la siguiente tabla...
Debe seleccionar un elemento de la lista desplegable para ver su descripción.
Esta página se ha desarrollado a partir de un par de mensajes de foros del web: Manipular array y Métodos de Arrays. Donde hemos participado: furoya, kepawe, Beakdan y yo (caricatos).
Array.prototype.cambiar = function(a, b) { var yo = this; if (a < 0 || a >= yo.length || b < 0 || b >= yo.length) return yo; var temp = yo[a]; yo[a] = yo[b]; yo[b] = temp; return yo; }
Array.prototype.moverPrimeroA = function(b) { var yo = new Array(); yo = this; var longitudArray = yo.length; if (b == yo.length - 1) return yo.rotarI(); else { if (b < (longitudArray)) { principio = new Array(); principio = yo.slice(0, parseInt(b) + 1); principio.length = parseInt(b) + 1; fin = new Array(); fin = this.slice(parseInt(b) + 1, longitudArray); principio = principio.rotarI().concat(fin); return principio; } else return yo; } }
Array.prototype.moverAlFinal = function(b) { var yo = this; var longitudArray = yo.length; if (b == 0) return yo.rotarI(); else { if (b < (yo.length - 1)) { principio = yo.slice(0, b); fin = yo.slice(b, longitudArray).rotarI(); yo = principio.concat(fin); return principio.concat(fin); } else return yo; } }
Array.prototype.mover = function(a, b) { var rotar = "rotarI"; var yo = this; var longitudArray = yo.length; if (a < 0 || b < 0) return yo; if (a == 0) return yo.moverPrimeroA(b); if (b == (yo.length - 1)) return yo.moverAlFinal(a); if (a > b) {temp = a; a = b; b = temp; rotar = "rotarD";} if (a > 0 && b < longitudArray) { principio = yo.slice(0, parseInt(a)); mitad = yo.slice(parseInt(a), parseInt(b) + 1)[rotar](); fin = yo.slice(parseInt(b) + 1, longitudArray); return principio.concat(mitad, fin); } return yo; }
function move1(alfa,bravo){ if(alfa=0 && bravo =0 ){ foxtrot = this.slice(alfa,alfa+1); if(alfa < bravo){ charly = this.slice(0,alfa); delta = this.slice(alfa+1,bravo+1); eco = this.slice(bravo+1,this.length); golf = charly.concat(delta.concat(foxtrot.concat(eco))); } else if(alfa > bravo){ charly = this.slice(0,bravo); delta = this.slice(bravo,alfa); eco = this.slice(alfa+1,this.length); golf = charly.concat(foxtrot.concat(delta.concat(eco))); } else golf = this; } return golf; } Array.prototype.move1 = move1;
Array.prototype.move_to = function() { // rota los elementos a la derecha if (arguments[0] == "right") { a = this.length - 1; b = 0; } // rota los elementos a la izquierda else if(arguments[0] == "left") { a = 0; b = this.length - 1; } // mueve un elemento a una posición else { a = arguments[0]; b = arguments[1]; } a = a >= this.length ? this.length - 1 : a < 0 ? 0: a; b = b >= this.length ? this.length - 1 : b < 0 ? 0: b; var element_move = this[a]; if(a < b) { for(var ctr = a; ctr < b; ctr++) { this[ctr] = this[ctr+1]; } } if(a > b) { for(var ctr = a; ctr > b; ctr--) { this[ctr] = this[ctr-1]; } } this[b] = element_move; return this; }
Array.prototype.invertir = function() {// reverse() for (var i = 0, mayor = parseInt(this.length / 2); i < mayor; i ++) this.cambiar(i, this.length - 1 - i); return this; }
// es código nativo
Array.prototype.rotarI = function() { var yo = this; var primero = yo.desapilarPrimero(); yo[yo.length] = primero; return yo; }
Array.prototype.rotarD = function() { var yo = this; var primero = new Array(); primero[0] = yo.desapilarUltimo(); primero = primero.concat(yo); return primero; }
Array.prototype.RotarD = function() { if(this.length > 0) { var last_element = this[this.length-1]; for(var ctr = this.length -1; ctr > 0; ctr--) this[ctr] = this[ctr-1]; this[0] = last_element; } return this; }
// es código nativo
// es código nativo
Array.prototype.shuffle = function(){ romeo = this; papa = romeo.length; for (sierra = 0;sierra < papa; sierra ++) { quebec = romeo[sierra]; tango = Math.floor(Math.random()*papa); romeo[sierra] = romeo[tango]; romeo[tango] = quebec; } return romeo; }
Array.prototype.random_array = function() { var ctr = 0; while(ctr < this.length) { var a = Math.floor(this.length* Math.random()); var b = Math.floor(this.length* Math.random()); this.move_to(a,b); ctr++; } return this; }
// es código nativo
Array.prototype.desapilarUltimo = function() {//pop() devolver = this[this.length - 1]; this.length--; return devolver; }
La verdad es que sobre los arrays asociativos, no hay mucho que decir, ya que se trata de una forma de tratar los mismos arrays sencillos, pero especialmente el tratamiento de arrays de objetos.
La verdad es que el tratamiento habitual de un array es "asociativo", pero con respecto a su índice en el orden de los elementos.
Por ejemplo, si tenemos en cuenta estas 2 imágenes (las únicas declaradas en esta página)
,
tienen el nombre "emoticoncito1" y "emoticoncito2"... y sus respectivos stributos id son:
"_emoticoncito1" y "_emoticoncito2" (se parecen a sus respectivos nombre, pero difieren).
Podemos referenciar a la primera tanto por su orden dentro del array de imágenes (document.images) del documento, como por el valor de su atributo name.
Por ejemplo, si queremos saber cual es el atributo src de la primera imagen podemos usar esta línea: alert(document.images[0].src)... pero también podemos saber cuál es el mismo atributo de la imagen cuyo atributo name es emoticoncito2 así: alert(document.images['emoticoncito1'].src). Y afinando más, podemos seleccionar los objetos a través de cualquier atributo: onclick="alert(document.images[id='_emoticoncito2'].name)
Entenderemos por colecciones, a los elementos iguales que se encuentran en una página web.
Los básicos serían: imágenes (images), formularios (forms), enlaces (links), anclas o puntos de anclaje (anchors), elementos incrustados -suelen ser multimedia- (embeds), aplicaciones java (applets), elementos de formulario ([el_formulario].elements), opciones de los selects [el_select].options), las filas de las tablas ([la_tabla].rows ...
Y otra calificación especial se correspondería con las colecciones de etiquetas iguales [base].getElementsByTagName(nombre_de_etiqueta), los nodos que "cuelgan" de un nodo "padre" ([el_nodo].childNodes)...
Esta pagina aún no tiene comentarios.
Valoración de esta página: (pagina.Arrays)