0
Hello
I have a functional example of data query searching the zip, the data are returning in the format:
    function searchCep () {
        // Recupera o value do input cep
        let cep = document.getElementById('cep').value
        // Inicia requisição AJAX com o axios
        axios.get(`http://api.postmon.com.br/v1/cep/${cep}`)
                .then(response => {
                                                console.log(response.data)
                    showResults (response.data)
                })
                .catch(error => {
                    // console.log(error)
                    // Mostra a div com o erro
                    document.getElementById('error').style.display = 'block'
                    // Mostra a mensagem
                    document.getElementById('error').innerHTML = 'Erro inesperado'
                })
                .finally(() => endPreloader ())
        event.preventDefault()
    }
function showResults(registros) {
    console.log(registros)
    console.log(`<p><b>Estado: </b> ${registros.nome} </p>`)
    // Mostra a div com o resultado
    document.getElementById('results').style.display = 'block'
    // Mostra os resultados:
    document.getElementById('results').innerHTML = `
                <p><b>ID: </b> ${dados.id} </p>
                <p><b>Nome: </b> ${dados.nome} </p>
                <p><b>Sexo: </b> ${dados.sexo} </p>
                <p><b>Estado: </b> ${dados.estado} </p>
            `
}
This model works, but if I have data in another format, I cannot capture the information, although they return;


If you are returning an array of objects, just make a loop and inside put the function showresults()
– Everton Neri
@Evertonneri, the problem is that in the format it comes [{"id:"3}] as it is coming with [], so I’m not getting the content
– Harry
the first print is returned a "{}" object, the second an "[]" array of "{}" objects is returned, which would be something like this: "[{},{},{} ...]"
– RDyego