i´m stuck at a little demo project from udemy with django and api calls. I have this in main.js and I want to get array of object and not just a json list in console.
let projectsUrl = 'http://127.0.0.1:8000/api/projects/'
let getProjects = () => {
fetch(projectsUrl)
.then(response => response.json())
.then(data => {
console.log(data)
buildProjects(data)
})
}
let buildProjects = (projects) => {
let projectsWrapper = document.getElementById('testz')
for (let i = 0; projects.lenght > i; i++){
let project = projects[i]
console.log(project)
}
}
getProjects()
The result :
and the result should be something like this :
There is a typo.
change
projects.lenght
to
projects.length