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

139
Visualizações
How to display object from json in js

I have json code

{
    "dezui": {
        "title": "DezUI CSS Framework",
        "description": "",
        "organizer": [""],
        "status": true,
        "homepage": "",
        "link": [""],
        "date": [18, 10, 2021],
        ...
    },
    ...
}

I want to display with loop in my page. Previous json code:

{
    "portfolio": [
        {
            "title": "DezUI CSS Framework",
            "description": "",
            "organizer": [""],
            "status": true,
            "homepage": "",
            ...
        },
        ...
    ]
}

With the previous code, I display the data with the code below:


fetch("/portfolio/portfolio.json")
.then(response => {return response.json()})
.then(data => {
    for (let i = 0; i < data.portfolio.length; i++) {
        if (data.portfolio[i].status == true) {
            document.getElementById("portfolio").innerHTML += `<div id="card-project"><div id="thumbnail"><a href="/portfolio/${data.portfolio[i].homepage}"><img src="/portfolio/thumbnails/${data.portfolio[i].thumbnail}"></a></div><h6 id="tag">${data.portfolio[i].tag}</h6><h6 id="title"><a href="/portfolio/${data.portfolio[i].homepage}">${data.portfolio[i].title}</a></h6></div>`
        }
    }
})

I'm confused how I display in the form of an object(?)

Please help me

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

0

Since your data shape changed you'll need to update your code. You no longer need to loop through it as there is only one entry. So you can reference that object and change it from portfolio to dezui. ex:

fetch("/portfolio/portfolio.json")
    .then(response => {return response.json()})
    .then(data => {
        if (data.dezui.status == true) {
            document.getElementById("portfolio").innerHTML += `<div id="card-project"><div id="thumbnail"><a href="/portfolio/${data.dezui.homepage}"><img src="/portfolio/thumbnails/${data.dezui.thumbnail}"></a></div><h6 id="tag">${data.dezui.tag}</h6><h6 id="title"><a href="/portfolio/${data.dezui.homepage}">${data.dezui.title}</a></h6></div>`
    }
})
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