Please I Need Help From A Good Javascript Programmer - Programming - Nairaland
Nairaland Forum › Science/Technology › Programming › Please I Need Help From A Good Javascript Programmer (780 Views)
1 Reply
| Please I Need Help From A Good Javascript Programmer by Weezyval(op): 11:31pm On Jun 29, 2015 |
please i need help...who can help me loop through this json object, i want to loop through the daily object using javascript but am having some difficulties. my code success: function(json) { console.log(json); $("#current_temp" .html(Math.round(json.currently.temperature)+"°F" ;$("#current_summary" .html(json.currently.summary); $("#current_temp" .attr("data-icon",icons[json.currently.icon]+" " ;$("#timezone" .html(json.timezone);var newDate = new Date(); newDate.setTime(json.currently.time*1000); dateString = newDate.toUTCString(); document.getElementById("time" .innerHTML = newDate;for ( var i = 0; i < daily.data.length; i++) { var DOM = jQuery('#DOM'); var obj = data[i]; console.log(obj); DOM.append("<li>"+obj.summary+"<li>" ; }; }, error: function(e) { console.log(e.message); } I will be very gratefull if anyone can help me out. Thanks the json object from the callback function Object { latitude: 41.879003, longitude: -87.63675, timezone: "America/Chicago", offset: -5, currently: Object, minutely: Object, hourly: Object, daily: Object, alerts: Array[1], flags: Object } the json Daily data structure(They are 8 in number) The second image is an expanded view of one of the daily object
|
| Re: Please I Need Help From A Good Javascript Programmer by IamGodzilla: 1:36pm On Jun 30, 2015 |
I don't really understand how your code is, because of the way it's formatted. But looking at the photo you attached. to loop through an array [], you do this. for (var i=0 i< daily.length; i++){And to loop through an object {}, you do this. for(var key in object){This is just an example of how you would loop. you probably are looping through an object using the array format. Also where you have daily.data.length, try daily.data[i], however I would recommend you save it to a variable, e.g var newVar = daily.data; |
| Re: Please I Need Help From A Good Javascript Programmer by Weezyval(op): 9:49am On Jul 02, 2015 |
IamGodzilla:ok' thanks a lot I appreciate |
Lets Start A Real Web-deveopment Course Here Html+css+javascript+php+mysql • Were Can I Download Free Video Tutorials On Javascript Or Ruby • My Web Development Consultancy Thread(html, CSS, Javascript, Jquery, ASP.NET) • 2 • 3 • 4
Xpath Injection • Uploading Software Created In Vb6 To A Website • ....
.html(Math.round(json.currently.temperature)+"°F"