获取数组索引的值

Get the value of the array index

本文关键字:索引 数组 获取      更新时间:2024-01-08

我有一个ajax响应数组,我想得到那里索引的值。

[{"用户纬度":"33.7543","用户经度":"-84.3744"}{"UserLatitude":"22.6962","UserLongitude":"75.8651"},{"UserLatitude:"22.6963","User经度":"75.8654 122.406"},{"用户纬度":"37.7858","用户经度":"-122.406"},"User经度":"-122.406"},{"UserLatitude":"0","UserLongitude":"0"}":"-84.3745"},{"UserLatitude":"0","UserLongitude":"0"},{"用户纬度":"33.7543","用户经度":"-84.3744"}]

第一个数组对象后面缺少一个逗号,导致错误。否则result[0].UserLatitude将起作用-jsfiddle。

您需要迭代数组,然后检查这些值是否像一样匹配

$.each (arr, function (index, value) { 
    if(value["UserLatitude"] == "33.7543" && value["UserLongitude"] == "-84.3744") {
        console.log(index);
        return false;
    }
});

如果找到匹配项,则打印index并退出循环。

Fiddle