Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

173
Visualizações
Sorting to another array

I have a problem when trying to sort an array alphabetically into another array.

This is what the original array looks like:

var palavras = new Array(5);

palavras[0] = "Português";
palavras[1] = "Inglês";
palavras[2] = "Programação C";
palavras[3] = "Programação JS";
palavras[4] = "Educação Física";

I need to sort this array alphabetically into another array but I can't seem to get it to work.

This is the expected output of the other array:

arraySorted[0] = "Educação Física";
arraySorted[1] = "Inglês";
arraySorted[2] = "Português";
arraySorted[3] = "Programação C";
arraySorted[4] = "Programação JS";

I'm new to StackOverflow so I don't know how to use the tools to make it more understandable but I hope someone can help. Thanks!

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

If I understand correctly, You want to keep original array unsorted. So you have to create new array from original one:

arraySorted = palavras.slice()

and then you can sort:

arraySorted.sort()

Array.slice() returns new array, without any param it returns array with the same values and length. Array.sort() changes array original array so without slice you would have both arrays changed

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda