我有一个包含这些值的数组(从google.maps.LatLng返回):
var polygon = [
{ k=50.882917044569744, B=6.003985404968262},
{ k=50.88289589175401, B=6.003938466310501},
{ k=50.882934389871465, B=6.003895550966263},
{ k=50.88295554266969, B=6.003943160176277}
]
我想要具有最高B值的那个的键,所以在这种情况下它将是polygon[0]
我不知道该数组究竟是如何制作的,但是console.log()
会让我回归确切地说:
[df { k=50.882917044569744, B=6.003985404968262, toString=function(), meer...}, df { k=50.88289589175401, B=6.003938466310501, toString=function(), meer...}, df { k=50.882934389871465, B=6.003895550966263, toString=function(), meer...}, df { k=50.88295554266969, B=6.003943160176277, toString=function(), meer...}]
polygon[0]
会给我第一个对象。
答案 0 :(得分:1)
您始终可以使用以下内容迭代数组:
var polygon = [
{k: 50.882917044569744, B: 6.003985404968262},
{k: 50.88289589175401, B: 6.003938466310501},
{k: 50.882934389871465, B: 6.003895550966263},
{k: 50.88295554266969, B: 6.003943160176277}
];
var i, p;
for (i = 0; i < polygon.length; i++) {
if (p === undefined || p.k < polygon[i].k) {
p = polygon[i];
}
}
console.log(p);