I have a file that contains the object I want to manipulate. I think two for example. But when in the showArrayOrdenado() function I apply the sort() to order it, since it is about objects and not literals. don't order me My idea is that they are ordered by the name parameter of each object that makes up the array. It's possible?
function Sandskill(nom, edad, especialidad, comp) {
this.nombre = nom;
this.edad = edad;
if (especialidad == 1 || especialidad == 2 || especialidad == 3) {
if (especialidad == 1)
this.especialidad = "sistemas";
if (especialidad == 2)
this.especialidad = "web";
if (especialidad == 3)
this.especialidad = "multiplataforma";
} else {
this.especialidad = null;
}
this.comp = comp;
//GETTER
this.getNom = function() {
return this.nombre;
}
this.getEdad = function() {
return this.edad;
}
this.getEspecialidad = function() {
return this.especialidad;
}
this.getComp = function() {
return this.comp;
}
}
var s1 = new Sandskill("Pepe", "22", "1");
var s2 = new Sandskill("Juan", "22", "2", s1);
function mostrarArrayOrdenado() {
sandskillArray.sort();
for (i = 0; i < sandskillArray.length; i++) {
alert(sandskillArray[i].getNom() + " * " + sandskillArray[i].getEdad() + " * " + sandskillArray[i].getEspecialidad() + " * ")
}
}
The sort() method, as you can see on the MDN website , can receive a comparator function as a parameter that has the following form:
In your case, it could be something like: