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

288
Visualizações
how to fetch and call all values individually. here there is no name of array so how do i access this
{
"amazon": "",
"flipkart": "",
"snapdeal": "",
"ebay": "",
"paytm": "",
"croma": "",
"yebhi": "",
"indiatimes": "",
"homeshop18": "",
"naaptol": "",
"infibeam": "",
"tatacliq": "",
"shopclues": "",
"paytmmall": "",
"gadgets360": ""
}

here is my code:

function fetchProduct(){
    console.log(pro_input.value)
    fetch('https://price-api.datayuge.com/api/v1/compare/price? 
    api_key=...&id='+pro_input.value+'')
      .then(response =>{
          if(! response.ok){
            throw Error("Error");
          }
          return response.json();
      })
      .then(data =>{
        const html2 = data(product_comp =>{
          return `<div class = "product_list">
                    <div class ="pro_comparedprice">
                      <p>Amazon: ${product_comp.amazon}</p>
                      <p>flipkart: ${product_comp.flipkart}</p>
                      <p>snapdeal: ${product_comp.snapdeal}</p>
                      <p>ebay: ${product_comp.ebay}</p>
                      <p>paytm: ${product_comp.paytm}</p>
                      <p>croma: ${product_comp.croma}</p>
                      <p>yebhi: ${product_comp.yebhi}</p>
                      <p>indiatimes: ${product_comp.indiatimes}</p>
                      <p>homeshop18: ${product_comp.homeshop18}</p>
                      <p>naaptol: ${product_comp.naaptol}</p>
                      <p>infibeam: ${product_comp.infibeam}</p>
                      <p>tatacliq: ${product_comp.tatacliq}</p>
                      <p>shopclues: ${product_comp.shopclues}</p>
                      <p>paytmmall: ${product_comp.paytmmall}</p>
                      <p>gadgets360: ${product_comp.gadgets360}</p>
                    </div>
                  </div>`
        }).join("");
        console.log(html2);
        document.querySelector("#pro_comparedprice").insertAdjacentHTML('afterbegin',html2);
      })
      .catch(error =>{
        console.log(error);
      });
  }
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

In javascript, if you want to fetch data of an array X we use X.forEach()like :

X.forEach((item,index)=>{
   /*instructions*/
})

But with non-array objects it is a litle bit diffrent
Here we use Object.keys(X), that will return an array with all the properties of the X Object in one dimensional array (let's name arr)
Now we can just use a simple for loop to fetch and call every value individually :

let arr = Object.keys(X)
for(var i=0; i<arr.length; i++){
   X[arr[i]]
}
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