1. 程式人生 > 實用技巧 >根據A組數 篩選 B陣列中的資料

根據A組數 篩選 B陣列中的資料

需求: 在B中刪除A中出現的景區

A陣列:

  // 隱藏資料
  hideData = [
    '北閣佛燈',
    '筆架山宋窯舊址',
    '道韻樓',
    '鳳凰塔',
    '鳳翔峽旅遊風景區',
    '富麗公園',
    '海陽儒學宮',
    '華廈博物館',
    '黃埔軍校分校李厝祠',
    '己略黃公祠',
    '開元寺',
    '龍湖古寨',
    '千果山',
    '饒宗頤學術館',
    '石壁山風景區',
    '市博物館',
    '外江梨園公所',
    '許駙馬府',
    '幽峪逸林',
  ]
View Code

B陣列:原始資料跟以下格式一樣

    "data": [{
        "areaId": 116,
        "sceneryLevel": "其他",
        "longitude": 115.9958630000000,
        "latitude": 23.5810580000000,
        "areaName": "黃滿磜瀑布群",
        "parentAreaId": 144,
        "subscriberCount": 1329,
        "rank": 1
    }, {
        "areaId": 120,
        "sceneryLevel": "其他",
        
"longitude": 115.9019510000000, "latitude": 23.4959750000000, "areaName": "龍潭鎮關山村", "parentAreaId": 144, "subscriberCount": 582, "rank": 2 }, { "areaId": 119, "sceneryLevel": "其他", "longitude": 115.8277720000000, "latitude": 23.4210060000000, "areaName": "河婆街道三山國王祖廟",
"parentAreaId": 144, "subscriberCount": 515, "rank": 3 }, { "areaId": 112, "sceneryLevel": "4A", "longitude": 115.9968790000000, "latitude": 23.5813220000000, "areaName": "黃滿寨瀑布旅遊區", "parentAreaId": 144, "subscriberCount": 467, "rank": 4 }, { "areaId": 115, "sceneryLevel": "其他", "longitude": 115.9332120000000, "latitude": 23.5521900000000, "areaName": "大北山森林公園", "parentAreaId": 144, "subscriberCount": 393, "rank": 5 }]
View Code

資料處理:

 1   let C = [];
 2 
 3       B.map(v => {
 4 
 5         if (this.A.indexOf(v['areaName']) <= -1) {
 6 
 7           hideList.push(v)
 8 
 9         }
10       })