node.js - Need help to loop through and extract variable from a object within an array -


first of all, i´m noobie @ least in programming, , first project. seem stuck , need help. :)

mission:

im trying grab lat , lon variables mqtt stream, , return this

[{"lat":54.9619349,"lng":-1.6003813},{"lat":54.9656694,"lng":-1.5239833},{"lat":54.9696456,"lng":-1.5069755},{"lat":54.9378907,"lng":-1.5273729}] 

this how far got:

var msg.payload = {"id":10,"created":"2014-05-24t07:31:05","location":{"disposition":"mobile","waypoints":[ {"at":"friday","lat":43.64,"lon":10.73,"ele":"15"},{"at":"saturday","lat":43.68,"lon":10.78,"ele":"26"},{"at":"monday","lat":43.72,"lon":10.83,"ele":"43"},{"at":"tuesday","lat":43.41,"lon":10.36,"ele":"98"}]}};  (var = 0, l = msg.payload.location.waypoints.length; < l; i++) {     var obj = msg.payload.location.waypoints[i];      return obj } 

this gives me first object , not array above:

{"at":"friday","lat":43.64,"lon":10.73,"ele":"15"} 

confused! :)

you have make variable obj array, , push json objects lat & lon keys respective values array.

var obj = []; (var = 0, l = msg.payload.location.waypoints.length; < l; i++) {     obj.push({         "lat" : msg.payload.location.waypoints[i].lat,         "lon" : msg.payload.location.waypoints[i].lon     })      return obj } 

Comments

Popular posts from this blog

google api - Incomplete response from Gmail API threads.list -

Installing Android SQLite Asset Helper -

Qt Creator - Searching files with Locator including folder -