how can I sort in ascending order a table of positions stored in an array in javascript?

0

I'm doing a game that demands a table of positions, which is made up of the names of users entered and their respective final scores. I have doubts about how I could sort such data without getting messed up, since ordering the numerical part is easy, the problem for me would be the names that agree with that numerical ordering. For now I have the function done like this, there is no code of order since I have looked at ways to order, but all would separate the names of the scores and that is not what I am looking for.

The add feature called at the end of the game. Thank you in advance!

                            function agregar(){


                             persona=document.getElementById('nombre').value;// recibe el nombre ingresado desde otra funcion
                                if(persona==""){
                                    contj=contj+1;
                                    auxiliarPersona="Jugador "+contj;
                                    auxiliarPuntaje=contG;
                                           }
                                else{
                                auxiliarPuntaje=contG;
                                 auxiliarPersona=persona;
                                     }
                                tabla.push(auxiliarPersona,auxiliarPuntaje);
                                document.getElementById("tab").innerHTML=tabla;   
                            }  
    
asked by Ramirez Miguel 02.12.2018 в 17:32
source

1 answer

0

For now I have the function done that way, there is no sorting code since I have looked at ways of ordering, but all of them would separate the names of the scores and that is not what I am looking for.

The add feature called at the end of the game. Thank you in advance!

                        function agregar(){
                         persona=document.getElementById('nombre').value;// recibe el nombre ingresado desde otra funcion
                            if(persona==""){
                                contj=contj+1;
                                auxiliarPersona="Jugador "+contj;
                                auxiliarPuntaje=contG;
                                       }
                            else{
                            auxiliarPuntaje=contG;
                             auxiliarPersona=persona;
                                 }
                            tabla.push(auxiliarPersona,auxiliarPuntaje);
                            document.getElementById("tab").innerHTML=tabla;   
                        }  
    
answered by 02.12.2018 в 17:57