skip to Main Content

i want to extract the data from API individually , how to pull out the data from Array?

let {Array}=jsonData
`fetch("https://apis.ccbp.in/city-bikes?bike_name" + search, options)
.then(function(response){ 
 return response.json();
})
.then(function(jsonData){
let {Array}=jsonData

console.log(Array)
console.log(jsonData)'
})




o/p-undefined

o/p- Array [Object {}]
0: Object {city: "Moscow", id: "velobike-mosco.



2

Answers


  1. If you are getting data based on the query parameters called bike_name, you need to use template literal string for using a variable in the string. Use the arrow functions instead of traditional functions in the then() promise chain. The below code will help you.

     fetch(`https://apis.ccbp.in/city-bikes?bike_name=${value}`,{method:'GET',headers:{}})
    .then((response)=>{ 
     return response.json();
    })
    .then((jsonData){
    console.log(jsonData)'
    })
    
    Login or Signup to reply.
  2. Yeah so just loop over it with a for loop?

    fetch("https://apis.ccbp.in/city-bikes?bike_name")
    .then(function(response){ 
     return response.json();
    })
    .then(res => {
      for (const entry of res) {
        let {city, id, name} = entry;
        
        console.log(city, id, name);
        // then you can do whatever you'd like
      }
    })
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search