如何使用JavaScript在数组(堆栈或队列)中存储值

时间:2017-01-19 06:42:25

标签: javascript stack queue fifo

设备1详细信息:

&

设备2详细信息:

{
    "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
        }
    }]
}

我需要同时将这些设备的位置存储在单独的堆栈中,并根据设备提取

{
    "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
            }
        }

1 个答案:

答案 0 :(得分:0)

  1. array.splice()是你要找的东西。使用此代替unshift& pop。在这里阅读to enqueue use this& to dequeue use this