For a project utilizing the openweather api, I encountered fluctuating data based on the time of day it is viewed. My goal is to loop through the first 8 objects to identify a dt_txt value of 12:00:00. Once found, I intend to store this result in a variable for further manipulation.
Here is an example of how the data appears (displaying only the first index):
0:
dt: 1579316400
main: {temp: 271.29, feels_like: 259.49, temp_min: 271.29, temp_max: 272.35, pressure: 1026, …}
weather: [{…}]
clouds: {all: 100}
wind: {speed: 13.55, deg: 147}
snow: {3h: 5}
sys: {pod: "n"}
dt_txt: "2020-01-18 03:00:00"
__proto__: Object
This was my initial attempt:
for (let i = 0; i < 8; i++) {
if ((response.list[i].dt_txt).substring(11) === "12:00:00") {
var noon = indexOf("12:00:00")
console.log(noon);
Any insights would be greatly appreciated!
Edit After some reflection, I realized what I was overlooking!
The revised functioning code:
for (let i = 0; i < 8; i++) {
if ((response.list[i].dt_txt).substring(11) === "12:00:00") {
var noon = response.list[i]
console.log(noon);
var noon2 = response.list[i + 8]
console.log(noon2);