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

129
Visualizações
Getting "Uncaught (inPromise) TypeError: ... sort is not a function" while trying to sort json data that is coming from the API by date attribute

I am trying to sort json data that is coming from the API by date attribute. However it gives me the following error. Please help me.

<html>
    <head>
    <script>
        async function callAwsLambdaFunction() {
            fetch( 'URL',  {
                method: 'GET'
              })
            .then(response => response.json())
            .then((response) => {
                var json_obj = JSON.stringify(response.body);
                
                json_obj_sorted = json_obj.sort(function(a, b) {
                    var dateA = new Date(a.in_time), dateB = new Date(b.in_time);
                    return dateA - dateB;
                });

                console.log(json_obj_sorted);
                document.getElementById("myDiv").innerHTML = json_obj_sorted;
            });
        }
    </script>   
        <title>Test</title>
    </head>
    <body>
        <p>This is only a test, nothing else.</p>
        <p>Click below button to call API gateway and display result below!</p>
        <p><div id="myDiv"></div></p>
        <button onclick="callAwsLambdaFunction()">Click me!</button>
    </body>
</html>

I tried also Object.entries but i keep getting following error in my console: enter image description here

about 4 years ago · Juan Pablo Isaza
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