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

75
Visualizações
JSON array fetch using JS

I wanted some help with JSON fetching using JS, I'm working a library of images and I have a locally present json file which includes over 5000+ entries of images name, size, color and etc for clothing articles. I was able to fetch the images by doing this,

JS

fetch("dataset_api.json")
    .then(function (data) {
        return data.json();
    })


    .then(function (data) {
        console.log(data);
        for (var i = 0; i < data.length; i++) {
            var img = (data[i].images[1, 0, 2, 3].src)
            $(".app-right").append("<div class='grid' data-id= " + i + "> <img src=" + img + " class='imggrd' loading=lazy> </div>");
        }

Example of a json entry

dataset_api.json


color: "black"
desc: "Shirt by Sixth June"
gender: "male"
images: (4) [{…}, {…}, {…}, {…}]
retailPrice: 87
size: (4) ['S', 'M', 'L', 'XL']
title: "SHIRT"
url: "url"
..................

and append it in the HTML it self

..but the issue I'm facing right now is, I think the json has so many entries that It automatically converts them into batches of 100 so [0 to 99]

screenshot console

and so on, so If I want to get the next batch of images I have to change the value for " i " in the for loop in js to 99 or above to do that.

I was wondering if there is a way so that as soon as a user scroll to the bottom the JS automatically loads the next batch right after by the increment of 100. Also the main reason I'm not loading all the images at once is because it is really heavy for the machine to do so.

HTML

    <div class="app-right">
    </div>
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You actually get back an array of objects (as in your image attached), 5973 of them.

The [0 ... 99] etc is just easier for us to expand so that the expanded result is not huge.

To do what you wanted, you can look into what is called "infinite scroll". You can

  1. Find a way to let the API to return you data in chucks, such as 50 each time, and do the infinite scroll

  2. Fetch all data all at once, and only show more to the user when the user scroll down

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