saCityIds = [
    {
        "created_by_id": null,
        "updated_by_id": null,
        "created_on": "2021-07-02 10:55:07",
        "updated_on": "2022-03-28 18:05:52",
        "id": 16,
        "entry_context_id": 100,
        "serviceability_mode_id": 1,
        "serviceability_type_id": 3,
        "name": "Nelmangala 5K  B SA",
        "is_active": true,
        "lmd_fc_id": 238,
        "short_name": "NGK",
        "city_id": 1,
        "entry_context_ids": null
    },
    {
        "created_by_id": null,
        "updated_by_id": null,
        "created_on": "2021-09-01 16:41:53",
        "updated_on": "2021-09-08 23:25:37",
        "id": 19,
        "entry_context_id": 100,
        "serviceability_mode_id": 1,
        "serviceability_type_id": 3,
        "name": "Kanhai 5K DS  GU SA",
        "is_active": true,
        "lmd_fc_id": 241,
        "short_name": "K5S",
        "city_id": 18,
        "entry_context_ids": null
    },
    {
        "created_by_id": null,
        "updated_by_id": null,
        "created_on": "2021-11-16 10:23:58",
        "updated_on": "2022-04-16 17:03:08",
        "id": 24,
        "entry_context_id": 100,
        "serviceability_mode_id": 1,
        "serviceability_type_id": 3,
        "name": "Faridabad Sec 28 5K  GU SA",
        "is_active": true,
        "lmd_fc_id": 245,
        "short_name": "FSK",
        "city_id": 18,
        "entry_context_ids": null
    },
    {
        "created_by_id": null,
        "updated_by_id": null,
        "created_on": "2021-11-16 15:59:26",
        "updated_on": "2021-11-16 15:59:26",
        "id": 25,
        "entry_context_id": 100,
        "serviceability_mode_id": 1,
        "serviceability_type_id": 3,
        "name": "Kalyan LT 5K  M SA",
        "is_active": true,
        "lmd_fc_id": 246,
        "short_name": "KYK",
        "city_id": 4,
        "entry_context_ids": null
    },
    {
        "created_by_id": null,
        "updated_by_id": null,
        "created_on": "2021-11-29 18:28:57",
        "updated_on": "2022-04-11 20:22:12",
        "id": 10004,
        "entry_context_id": 100,
        "serviceability_mode_id": 1,
        "serviceability_type_id": 3,
        "name": "Mira-Road-LT-M-SA",
        "is_active": false,
        "lmd_fc_id": 248,
        "short_name": "MDT",
        "city_id": 4,
        "entry_context_ids": null
    },
    {
        "created_by_id": null,
        "updated_by_id": null,
        "created_on": "2021-12-12 19:28:20",
        "updated_on": "2022-03-22 19:25:34",
        "id": 10014,
        "entry_context_id": 100,
        "serviceability_mode_id": 1,
        "serviceability_type_id": 3,
        "name": "Chattarpur-GU-SA",
        "is_active": true,
        "lmd_fc_id": 255,
        "short_name": "SAM",
        "city_id": 18,
        "entry_context_ids": null
    },
    {
        "created_by_id": null,
        "updated_by_id": null,
        "created_on": "2021-12-12 19:39:11",
        "updated_on": "2022-05-19 19:33:21",
        "id": 10015,
        "entry_context_id": 100,
        "serviceability_mode_id": 1,
        "serviceability_type_id": 3,
        "name": "Sarita-Vihar-GU-SA",
        "is_active": true,
        "lmd_fc_id": 256,
        "short_name": "SV",
        "city_id": 18,
        "entry_context_ids": null
    },
    {
        "created_by_id": null,
        "updated_by_id": null,
        "created_on": "2021-12-12 19:45:38",
        "updated_on": "2022-02-15 19:13:09",
        "id": 10016,
        "entry_context_id": 100,
        "serviceability_mode_id": 1,
        "serviceability_type_id": 3,
        "name": "SPR-5K-GU-SA",
        "is_active": true,
        "lmd_fc_id": 257,
        "short_name": "S_K",
        "city_id": 18,
        "entry_context_ids": null
    },
    {
        "created_by_id": null,
        "updated_by_id": null,
        "created_on": "2021-12-12 19:50:15",
        "updated_on": "2021-12-12 19:50:15",
        "id": 10017,
        "entry_context_id": 100,
        "serviceability_mode_id": 1,
        "serviceability_type_id": 3,
        "name": "Udyog-Vihar-SA",
        "is_active": true,
        "lmd_fc_id": 258,
        "short_name": "UDV",
        "city_id": 18,
        "entry_context_ids": null
    },
    {
        "created_by_id": null,
        "updated_by_id": null,
        "created_on": "2021-12-12 20:00:08",
        "updated_on": "2022-04-05 20:12:53",
        "id": 10018,
        "entry_context_id": 100,
        "serviceability_mode_id": 1,
        "serviceability_type_id": 3,
        "name": "Andheri-5K-DS-M-SA",
        "is_active": true,
        "lmd_fc_id": 259,
        "short_name": "N5S",
        "city_id": 4,
        "entry_context_ids": null
    },
    {
        "created_by_id": null,
        "updated_by_id": null,
        "created_on": "2021-12-12 20:05:45",
        "updated_on": "2022-03-31 21:04:29",
        "id": 10019,
        "entry_context_id": 100,
        "serviceability_mode_id": 1,
        "serviceability_type_id": 3,
        "name": "Bhandup-5K-M-SA",
        "is_active": true,
        "lmd_fc_id": 260,
        "short_name": "BDK",
        "city_id": 4,
        "entry_context_ids": null
    },
    {
        "created_by_id": null,
        "updated_by_id": null,
        "created_on": "2021-12-12 20:13:52",
        "updated_on": "2022-04-06 20:10:33",
        "id": 10020,
        "entry_context_id": 100,
        "serviceability_mode_id": 1,
        "serviceability_type_id": 3,
        "name": "Goregaon-5K-DS-M-SA",
        "is_active": true,
        "lmd_fc_id": 261,
        "short_name": "G5S",
        "city_id": 4,
        "entry_context_ids": null
    },
    {
        "created_by_id": null,
        "updated_by_id": null,
        "created_on": "2021-12-12 20:19:50",
        "updated_on": "2022-05-07 20:58:23",
        "id": 10021,
        "entry_context_id": 100,
        "serviceability_mode_id": 1,
        "serviceability_type_id": 3,
        "name": "Kurla-5K-M-SA",
        "is_active": true,
        "lmd_fc_id": 262,
        "short_name": "KUR",
        "city_id": 4,
        "entry_context_ids": null
    },
    {
        "created_by_id": null,
        "updated_by_id": null,
        "created_on": "2021-12-12 20:21:54",
        "updated_on": "2022-04-04 20:22:57",
        "id": 10022,
        "entry_context_id": 100,
        "serviceability_mode_id": 1,
        "serviceability_type_id": 3,
        "name": "Sewri-5K-M-SA",
        "is_active": true,
        "lmd_fc_id": 263,
        "short_name": "SRK",
        "city_id": 4,
        "entry_context_ids": null
    },
    {
        "created_by_id": null,
        "updated_by_id": null,
        "created_on": "2021-12-12 20:23:39",
        "updated_on": "2022-02-15 19:23:13",
        "id": 10023,
        "entry_context_id": 100,
        "serviceability_mode_id": 1,
        "serviceability_type_id": 3,
        "name": "Thane-5K-M-SA",
        "is_active": true,
        "lmd_fc_id": 264,
        "short_name": "TNK",
        "city_id": 4,
        "entry_context_ids": null
    },
    {
        "created_by_id": null,
        "updated_by_id": null,
        "created_on": "2021-12-12 20:25:40",
        "updated_on": "2022-04-06 20:15:29",
        "id": 10024,
        "entry_context_id": 100,
        "serviceability_mode_id": 1,
        "serviceability_type_id": 3,
        "name": "Vashi-5K-H-SA",
        "is_active": true,
        "lmd_fc_id": 265,
        "short_name": "VHF",
        "city_id": 4,
        "entry_context_ids": null
    },
    {
        "created_by_id": null,
        "updated_by_id": null,
        "created_on": "2021-12-13 16:52:30",
        "updated_on": "2022-05-20 15:10:56",
        "id": 10025,
        "entry_context_id": 100,
        "serviceability_mode_id": 1,
        "serviceability_type_id": 3,
        "name": "EPIP-5K-B-SA",
        "is_active": true,
        "lmd_fc_id": 266,
        "short_name": "EPB",
        "city_id": 1,
        "entry_context_ids": null
    },
    {
        "created_by_id": null,
        "updated_by_id": null,
        "created_on": "2021-12-13 22:14:47",
        "updated_on": "2022-05-16 19:37:01",
        "id": 10026,
        "entry_context_id": 100,
        "serviceability_mode_id": 1,
        "serviceability_type_id": 3,
        "name": "K-R-Puram-5K-B-SA",
        "is_active": true,
        "lmd_fc_id": 267,
        "short_name": "KRK",
        "city_id": 1,
        "entry_context_ids": null
    },
    {
        "created_by_id": null,
        "updated_by_id": null,
        "created_on": "2021-12-13 22:20:54",
        "updated_on": "2022-03-14 19:10:00",
        "id": 10027,
        "entry_context_id": 100,
        "serviceability_mode_id": 1,
        "serviceability_type_id": 3,
        "name": "Mahalakshmi-5K-B-SA",
        "is_active": true,
        "lmd_fc_id": 268,
        "short_name": "MSK",
        "city_id": 1,
        "entry_context_ids": null
    },
    {
        "created_by_id": null,
        "updated_by_id": null,
        "created_on": "2021-12-13 22:23:31",
        "updated_on": "2022-05-20 19:28:18",
        "id": 10028,
        "entry_context_id": 100,
        "serviceability_mode_id": 1,
        "serviceability_type_id": 3,
        "name": "Mahadevapura-5K-B-SA",
        "is_active": true,
        "lmd_fc_id": 269,
        "short_name": "MPK",
        "city_id": 1,
        "entry_context_ids": null
    },
    {
        "created_by_id": null,
        "updated_by_id": null,
        "created_on": "2021-12-13 22:25:01",
        "updated_on": "2022-03-15 19:55:39",
        "id": 10029,
        "entry_context_id": 100,
        "serviceability_mode_id": 1,
        "serviceability_type_id": 3,
        "name": "Yeshwantpura-5K-B-SA",
        "is_active": true,
        "lmd_fc_id": 270,
        "short_name": "YWK",
        "city_id": 1,
        "entry_context_ids": null
    },
    {
        "created_by_id": null,
        "updated_by_id": null,
        "created_on": "2021-12-13 22:29:20",
        "updated_on": "2022-03-15 19:57:39",
        "id": 10030,
        "entry_context_id": 100,
        "serviceability_mode_id": 1,
        "serviceability_type_id": 3,
        "name": "Tanisandra-5K-B-SA",
        "is_active": true,
        "lmd_fc_id": 271,
        "short_name": "TDK",
        "city_id": 1,
        "entry_context_ids": null
    },
    {
        "created_by_id": null,
        "updated_by_id": null,
        "created_on": "2021-12-13 22:31:43",
        "updated_on": "2022-04-13 20:24:13",
        "id": 10031,
        "entry_context_id": 100,
        "serviceability_mode_id": 1,
        "serviceability_type_id": 3,
        "name": "HRBR-5K-B-SA",
        "is_active": true,
        "lmd_fc_id": 272,
        "short_name": "HRK",
        "city_id": 1,
        "entry_context_ids": null
    },
    {
        "created_by_id": null,
        "updated_by_id": null,
        "created_on": "2021-12-13 22:35:09",
        "updated_on": "2022-05-17 19:26:16",
        "id": 10032,
        "entry_context_id": 100,
        "serviceability_mode_id": 1,
        "serviceability_type_id": 3,
        "name": "Siddhapura-5K-B-SA",
        "is_active": true,
        "lmd_fc_id": 273,
        "short_name": "SPK",
        "city_id": 1,
        "entry_context_ids": null
    },
    {
        "created_by_id": null,
        "updated_by_id": null,
        "created_on": "2021-12-16 20:38:51",
        "updated_on": "2022-01-31 15:53:06",
        "id": 10033,
        "entry_context_id": 100,
        "serviceability_mode_id": 1,
        "serviceability_type_id": 3,
        "name": "Ecity-5K-B-SA",
        "is_active": false,
        "lmd_fc_id": 274,
        "short_name": "CYK",
        "city_id": 1,
        "entry_context_ids": null
    },
    {
        "created_by_id": null,
        "updated_by_id": null,
        "created_on": "2021-12-16 20:43:28",
        "updated_on": "2022-06-08 11:59:33",
        "id": 10034,
        "entry_context_id": 100,
        "serviceability_mode_id": 1,
        "serviceability_type_id": 3,
        "name": "Hulimavu-5K-B-SA",
        "is_active": false,
        "lmd_fc_id": 450,
        "short_name": "HVK",
        "city_id": 1,
        "entry_context_ids": null
    },
    {
        "created_by_id": null,
        "updated_by_id": null,
        "created_on": "2022-02-18 07:53:38",
        "updated_on": "2022-02-22 14:00:55",
        "id": 10141,
        "entry_context_id": 100,
        "serviceability_mode_id": 1,
        "serviceability_type_id": 3,
        "name": "Bhiwadi-LT-DS-GU-SA",
        "is_active": true,
        "lmd_fc_id": 379,
        "short_name": "BLS",
        "city_id": 18,
        "entry_context_ids": null
    },
    {
        "created_by_id": null,
        "updated_by_id": null,
        "created_on": "2022-03-14 11:38:08",
        "updated_on": "2022-03-28 11:21:34",
        "id": 10179,
        "entry_context_id": 100,
        "serviceability_mode_id": 1,
        "serviceability_type_id": 3,
        "name": "Jayanagar-5K-B-SA",
        "is_active": false,
        "lmd_fc_id": 416,
        "short_name": "JGK",
        "city_id": 1,
        "entry_context_ids": null
    },
    {
        "created_by_id": null,
        "updated_by_id": null,
        "created_on": "2022-03-26 00:06:07",
        "updated_on": "2022-03-31 12:21:14",
        "id": 10187,
        "entry_context_id": 100,
        "serviceability_mode_id": 1,
        "serviceability_type_id": 3,
        "name": "Nashik-5K-M-SA",
        "is_active": false,
        "lmd_fc_id": 423,
        "short_name": "NSK",
        "city_id": 4,
        "entry_context_ids": null
    },
    {
        "created_by_id": null,
        "updated_by_id": null,
        "created_on": "2022-03-26 00:13:40",
        "updated_on": "2022-04-11 20:49:28",
        "id": 10188,
        "entry_context_id": 100,
        "serviceability_mode_id": 1,
        "serviceability_type_id": 3,
        "name": "Mira-Road-5K-M-SA",
        "is_active": true,
        "lmd_fc_id": 424,
        "short_name": "MDK",
        "city_id": 4,
        "entry_context_ids": null
    },
    {
        "created_by_id": null,
        "updated_by_id": null,
        "created_on": "2022-04-07 13:26:11",
        "updated_on": "2022-04-12 20:29:51",
        "id": 10213,
        "entry_context_id": 100,
        "serviceability_mode_id": 1,
        "serviceability_type_id": 3,
        "name": "JP-Nagar-5K-B-SA",
        "is_active": true,
        "lmd_fc_id": 449,
        "short_name": "JPK",
        "city_id": 1,
        "entry_context_ids": null
    },
    {
        "created_by_id": null,
        "updated_by_id": null,
        "created_on": "2022-04-09 11:55:25",
        "updated_on": "2022-04-18 20:28:37",
        "id": 10215,
        "entry_context_id": 100,
        "serviceability_mode_id": 1,
        "serviceability_type_id": 3,
        "name": "Bellandur-5K-B-SA",
        "is_active": true,
        "lmd_fc_id": 451,
        "short_name": "BRK",
        "city_id": 1,
        "entry_context_ids": null
    },
    {
        "created_by_id": null,
        "updated_by_id": null,
        "created_on": "2022-04-09 11:58:24",
        "updated_on": "2022-04-13 20:28:11",
        "id": 10216,
        "entry_context_id": 100,
        "serviceability_mode_id": 1,
        "serviceability_type_id": 3,
        "name": "Ittemadu-5K-B-SA",
        "is_active": true,
        "lmd_fc_id": 452,
        "short_name": "TIK",
        "city_id": 1,
        "entry_context_ids": null
    },
    {
        "created_by_id": null,
        "updated_by_id": null,
        "created_on": "2022-04-09 12:01:12",
        "updated_on": "2022-05-19 19:28:10",
        "id": 10217,
        "entry_context_id": 100,
        "serviceability_mode_id": 1,
        "serviceability_type_id": 3,
        "name": "Kudlu-5K-B-SA",
        "is_active": true,
        "lmd_fc_id": 453,
        "short_name": "KLK",
        "city_id": 1,
        "entry_context_ids": null
    },
    {
        "created_by_id": null,
        "updated_by_id": null,
        "created_on": "2022-04-09 12:03:33",
        "updated_on": "2022-05-24 13:46:26",
        "id": 10218,
        "entry_context_id": 100,
        "serviceability_mode_id": 1,
        "serviceability_type_id": 3,
        "name": "Sarjapur-5K-B-SA",
        "is_active": true,
        "lmd_fc_id": 454,
        "short_name": "SPK",
        "city_id": 1,
        "entry_context_ids": null
    },
    {
        "created_by_id": null,
        "updated_by_id": null,
        "created_on": "2022-04-09 14:36:29",
        "updated_on": "2022-05-18 19:23:13",
        "id": 10219,
        "entry_context_id": 100,
        "serviceability_mode_id": 1,
        "serviceability_type_id": 3,
        "name": "Dwarka-GU-SA",
        "is_active": true,
        "lmd_fc_id": 455,
        "short_name": "DWG",
        "city_id": 18,
        "entry_context_ids": null
    },
    {
        "created_by_id": null,
        "updated_by_id": null,
        "created_on": "2022-04-09 14:47:08",
        "updated_on": "2022-05-17 19:32:47",
        "id": 10220,
        "entry_context_id": 100,
        "serviceability_mode_id": 1,
        "serviceability_type_id": 3,
        "name": "East-Delhi-KU-5K-GU-SA",
        "is_active": true,
        "lmd_fc_id": 456,
        "short_name": "SHK",
        "city_id": 18,
        "entry_context_ids": null
    },
    {
        "created_by_id": null,
        "updated_by_id": null,
        "created_on": "2022-04-09 14:51:18",
        "updated_on": "2022-05-16 19:26:35",
        "id": 10221,
        "entry_context_id": 100,
        "serviceability_mode_id": 1,
        "serviceability_type_id": 3,
        "name": "Okhla-5K-H-SA",
        "is_active": true,
        "lmd_fc_id": 457,
        "short_name": "OLH",
        "city_id": 18,
        "entry_context_ids": null
    },
    {
        "created_by_id": null,
        "updated_by_id": null,
        "created_on": "2022-04-09 14:55:05",
        "updated_on": "2022-05-19 21:23:40",
        "id": 10222,
        "entry_context_id": 100,
        "serviceability_mode_id": 1,
        "serviceability_type_id": 3,
        "name": "Kundli-LT-GU-SA",
        "is_active": true,
        "lmd_fc_id": 458,
        "short_name": "KLT",
        "city_id": 18,
        "entry_context_ids": null
    },
    {
        "created_by_id": null,
        "updated_by_id": null,
        "created_on": "2022-04-09 15:15:31",
        "updated_on": "2022-06-08 12:35:00",
        "id": 10223,
        "entry_context_id": 100,
        "serviceability_mode_id": 1,
        "serviceability_type_id": 3,
        "name": "Peeragarhi-5K-GU-SA",
        "is_active": false,
        "lmd_fc_id": 510,
        "short_name": "PRK",
        "city_id": 18,
        "entry_context_ids": null
    },
    {
        "created_by_id": null,
        "updated_by_id": null,
        "created_on": "2022-05-12 15:39:35",
        "updated_on": "2022-06-09 13:06:42",
        "id": 10259,
        "entry_context_id": 100,
        "serviceability_mode_id": 1,
        "serviceability_type_id": 3,
        "name": "Bahadurgarh-LT-KU-5K-GU-SA",
        "is_active": true,
        "lmd_fc_id": 482,
        "short_name": "BLG",
        "city_id": 18,
        "entry_context_ids": null
    },
    {
        "created_by_id": null,
        "updated_by_id": null,
        "created_on": "2022-05-12 15:52:40",
        "updated_on": "2022-05-19 19:34:22",
        "id": 10260,
        "entry_context_id": 100,
        "serviceability_mode_id": 1,
        "serviceability_type_id": 3,
        "name": "Samalka-GU-SA",
        "is_active": true,
        "lmd_fc_id": 483,
        "short_name": "SAM",
        "city_id": 18,
        "entry_context_ids": null
    },
    {
        "created_by_id": null,
        "updated_by_id": null,
        "created_on": "2022-06-09 13:42:57",
        "updated_on": "2022-06-09 13:44:50",
        "id": 10349,
        "entry_context_id": 100,
        "serviceability_mode_id": 1,
        "serviceability_type_id": 3,
        "name": "EPIP-SR-5K-B-SA",
        "is_active": false,
        "lmd_fc_id": 571,
        "short_name": "PSK",
        "city_id": 1,
        "entry_context_ids": null
    },
    {
        "created_by_id": 1,
        "updated_by_id": null,
        "created_on": "2022-07-04 12:02:40",
        "updated_on": "2022-07-04 12:03:58",
        "id": 10367,
        "entry_context_id": 100,
        "serviceability_mode_id": 3,
        "serviceability_type_id": 11,
        "name": "Hqa-Regression-SA",
        "is_active": true,
        "lmd_fc_id": 472,
        "short_name": "HRS",
        "city_id": 1,
        "entry_context_ids": null
    }
]
segment = {
                            "type": ["SA","DS"],
                            "cities":[1,4,18],
                            "ds_values":{"cid_1":[1,2,3,4,5]},
                            "ds_labels":{"cid_1":[1,2,3,4,5]},
                            "city_level": false
                            };
let saList = []
segment.cities.forEach(function(value){
  saCityIds.every(function(val){
                    if (val["city_id"] === value)
                    {
                      saList.push(val["id"])
                      return false
                    }
                    return true
                    
                });
  
});

let sa_newList = []
let empty = []
saCityIds.forEach(function(val){
                    if (empty.includes(val["city_id"]) == false)
                    
                    {
                      sa_newList.push(val["id"])
                      empty.push(val["city_id"])
                    }

});

                
console.log(saList)
console.log(sa_newList) 
by

NodeJS Online Compiler

Write, Run & Share NodeJS code online using OneCompiler's NodeJS online compiler for free. It's one of the robust, feature-rich online compilers for NodeJS language,running on the latest LTS version NodeJS 16.14.2. Getting started with the OneCompiler's NodeJS editor is easy and fast. The editor shows sample boilerplate code when you choose language as NodeJS and start coding. You can provide the dependencies in package.json.

About NodeJS

Node.js is a free and open-source server environment. Node.js is very popular in recent times and a large number of companies like Microsoft, Paypal, Uber, Yahoo, General Electric and many others are using Node.js.

Key features

  • Built on Google chrome's javascript engine V8 and is pretty fast.
  • Node.js was developed by Ryan Dahl in 2009.
  • Server-side platform for building fast and scalable applications.
  • Node.js is Asynchronous, event-driven and works on single-thread model thus eliminating the dis-advantages of multi-thread model.
  • Supports various platforms like Windows, Linux, MacOS etc.
  • Provides rich library of java script modules which simplifies the development efforts.
  • Released under MIT license.

Express Framework

Express is one of the most popular web application framework in the NodeJS echosystem.

  • Pretty fast
  • Minimalist
  • Unopinionated
  • Very flexible

Syntax help

Examples

Using Moment

let moment = require('moment');

console.log(moment().format('MMMM Do YYYY, h:mm:ss a'));

Using Lodash

const _ = require("lodash");

let colors = ['blue', 'green', 'yellow', 'red'];

let firstElement = _.first(colors);
let lastElement = _.last(colors);

console.log(`First element: ${firstElement}`);
console.log(`Last element: ${lastElement}`);

Libraries supported

Following are the libraries supported by OneCompiler's NodeJS compiler.

  • lodash
  • moment
  • underscore
  • uuid
  • ejs
  • md5
  • url