Nirodha Wickramarathna
Nirodha Wickramarathna

Reputation: 291

How I get value from JSON React Native?

This is my JSON response. Can you please tell me how can I get daily array values? When I print console.log(data.timezone), It is working but how can I print daily[0].temp[0].day

{
  "lat": 7.3127,
  "lon": 80.6831,
  "timezone": "Asia/Colombo",
  "daily": [
    {
      "dt": 1639290600,
      "sunrise": 1639269596,
      "temp": {
        "day": 28.45,
        "min": 19.96,
        "max": 28.6,
      }
    },
    {
      "dt": 1639290600,
      "sunrise": 1639269596,
      "temp": {
        "day": 28.45,
        "min": 19.96,
        "max": 28.6,
      }
    }
    {
      "dt": 1639290600,
      "sunrise": 1639269596,
      "temp": {
        "day": 28.45,
        "min": 19.96,
        "max": 28.6,
      }
    }
    
  ]
}

Upvotes: 0

Views: 214

Answers (2)

Code Awesome
Code Awesome

Reputation: 181

daily = data.daily
for(let i=0; i < daily.length; i++){
console.log(daily[i].temp.day)
}

Upvotes: 1

H9ee
H9ee

Reputation: 420

temp is not array ! is Object so you cant get index

console.log(data.daily[0].temp.day)

Upvotes: 0

Related Questions