i have a this code:
fetch("https://rickandmortyapi.com/api/character/?name=Rick")
.then((response) => {
response.json().then((data) => {
console.log(JSON.stringify(data))
}).catch( (error) => {
console.log(`Error: ${error}`)
})
})
with the given API endpoint, the function returns an array of objects. I want to access a specific index within the returned data object but am struggling to do so. Can anyone provide an explanation of how JSON objects work with response.json() and whether they differ from regular JavaScript objects? Thank you.
Edit: here is what the code outputs:
{"info":{"count":107,"pages":6,"next":"https://rickandmortyapi.com/api/character/?page=2&name=Rick","prev":null},"results":[{"id":1,"name":"Rick Sanchez","status":"Alive","species":"Human","type":"","gender":"Male","origin":{"name":"Earth (C-137)","url":"https://rickandmortyapi.com/api/location/1"},"location":{"name":"Citadel of Ricks","url":"https://rickandmortyapi.com/api/location/3"},"image":"https://rickandmortyapi.com/api/character/avatar/1.jpeg","episode":[&...