how to store values in an array (stack or queue) using JavaScript -
device 1 details:
{ "positions": [{ "address": "1326 13 cross rd, bengaluru, ka, in", "protocol": "osmand", "fixtime": "2017-01-19t11:58:40.000+05:30", "devicetime": "2017-01-19t11:58:40.000+05:30", "latitude": 12.9750062, "longitude": 77.63568398, "valid": true, "speed": 0.0, "outdated": false, "altitude": 808.0, "course": 0.0, "deviceid": 2, "id": 545, "attributes": { "battery": "62.0", "ip": "192.168.0.107", "distance": 0.13, "totaldistance": 3307.1 } }] }
device 2 details :
{ "positions": [{ "address": "1326 13 cross rd, bengaluru, ka, in", "protocol": "osmand", "fixtime": "2017-01-18t17:38:29.000+05:30", "devicetime": "2017-01-18t17:38:29.000+05:30", "latitude": 12.9750375, "longitude": 77.6356692, "servertime": "2017-01-18t17:38:31.000+05:30", "valid": true, "speed": 0.0, "outdated": false, "altitude": 0.0, "course": 0.0, "deviceid": 1, "id": 262, "attributes": { "battery": "55.0", "ip": "192.168.0.108", "distance": 0.0, "totaldistance": 26.96 } }
i need store position of these devices in separate stack simultaneously , fetched according device
function updatemaplive(positions) { (i = 0; < positions.length; i++) { console.log(positions[i].longitude + "," + positions[i].latitude); var latlong = positions[i].longitude + "," + positions[i].latitude; var deviceid = positions[i].deviceid; var q = new queue(); q.enqueue(latlong); arr.push(latlong); console.log(deviceid); } } function queue() { this.stac = new array(); this.dequeue = function () { return this.stac.pop(); } this.enqueue = function (item) { this.stac.unshift(item); } }
array.splice()
thing looking for. use instead ofunshift
&pop
. read here to enqueue use this & to dequeue use this.
Comments
Post a Comment