第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何過濾和查找對象內部

如何過濾和查找對象內部

瀟湘沐 2023-04-20 10:04:38
我想在 branches 數(shù)組中搜索 finder 對象,如果找到匹配項,那么我想獲取 finder 對象的位置名稱。var branches= [  {    locationName: "Cool Towers",    coordinates: [      {        latitude: 25.33853805869942,        longitude: 55.393801012135796,      },      {        latitude: 25.33848836326937,        longitude: 55.393874772883706,      },      {        latitude: 25.338230189121408,        longitude: 55.39362935075884,      }    ],  },  {    locationName:"Great Towers",    coordinates: [      {        latitude: 25.16626719853835,        longitude: 55.26170584184425,      },      {        latitude: 25.166607063076132,        longitude: 55.26206257564323,      }    ],  }]var finder =   {        latitude: 25.166607063076132,        longitude: 55.26206257564323,  }本案例預期結果為:Great Towers這就是我嘗試過的。但這總是給我第一個位置名稱const filter = Object.entries(finder),  result = branches    .filter(({ coordinates }) =>      filt.every(([key, value]) => coordinates[key] === value)    )    .map(({ locationName }) => locationName);
查看完整描述

4 回答

?
胡說叔叔

TA貢獻1804條經(jīng)驗 獲得超8個贊

這將找到坐標等于的分支finder


var branches = [

  {

locationName: "Cool Towers",

coordinates: [

  {

    latitude: 25.33853805869942,

    longitude: 55.393801012135796,

  },

  {

    latitude: 25.33848836326937,

    longitude: 55.393874772883706,

  },

  {

    latitude: 25.338230189121408,

    longitude: 55.39362935075884,

  }

],

  },

  {

locationName:"Great Towers",

coordinates: [

  {

    latitude: 25.16626719853835,

    longitude: 55.26170584184425,

  },

  {

    latitude: 25.166607063076132,

    longitude: 55.26206257564323,

  }

],

  }

];


var finder = {

latitude: 25.166607063076132,

longitude: 55.26206257564323,

}


var branch = branches.find(branch => {

return branch.coordinates.find(coordinate => {

    return coordinate.latitude == finder.latitude && 

           coordinate.longitude == finder.longitude

})

});


console.log(branch.locationName)


查看完整回答
反對 回復 2023-04-20
?
皈依舞

TA貢獻1851條經(jīng)驗 獲得超3個贊

您可以使用find來實現(xiàn)您想要做的事情:


const match = branches.find((branch) => {

? return branch.coordinates.find((coords) => {

? ? return finder.longitude === coords.longitude && finder.latitude === coords.latitude

? });

});


查看完整回答
反對 回復 2023-04-20
?
料青山看我應如是

TA貢獻1772條經(jīng)驗 獲得超8個贊

您可以使用Array.find和Array.findIndex來完成

const branches = [

? {

? ? locationName: "Cool Towers",

? ? coordinates: [

? ? ? {

? ? ? ? latitude: 25.33853805869942,

? ? ? ? longitude: 55.393801012135796,

? ? ? },

? ? ? {

? ? ? ? latitude: 25.33848836326937,

? ? ? ? longitude: 55.393874772883706,

? ? ? },

? ? ? {

? ? ? ? latitude: 25.338230189121408,

? ? ? ? longitude: 55.39362935075884,

? ? ? }

? ? ],

? },

? {

? ? locationName:"Great Towers",

? ? coordinates: [

? ? ? {

? ? ? ? latitude: 25.16626719853835,

? ? ? ? longitude: 55.26170584184425,

? ? ? },

? ? ? {

? ? ? ? latitude: 25.166607063076132,

? ? ? ? longitude: 55.26206257564323,

? ? ? }

? ? ],

? }

];


const finder = {

? latitude: 25.166607063076132,

? longitude: 55.26206257564323

};


const findCoordinate = (co) => {

? return (co.latitude === finder.latitude) && (co.longitude === finder.longitude);

}


const branch = branches.find((item) => item.coordinates.findIndex(findCoordinate) >= 0);

if (branch) {

? console.log(branch.locationName);

} else {

? // Not found

}



查看完整回答
反對 回復 2023-04-20
?
忽然笑

TA貢獻1806條經(jīng)驗 獲得超5個贊

let result;

for(let i = 0; i < branches.length; i++) {

    if (branches[i].coordinates.findIndex(coord => coord.latitude === finder.latitude && coord.longitude === finder.longitude) >= 0 ) {

      result = branches[i].locationName;

      break;

    }  

}

console.log(result);


查看完整回答
反對 回復 2023-04-20
  • 4 回答
  • 0 關注
  • 167 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網(wǎng)微信公眾號