Javascript 多维数组中的键值对搜索
非常感谢您的阅读 我有一个JSON对象需要搜索,以确定是否存在值。我遇到的问题是查看一个数组,然后在功能数组中,测试是否存在“底层池” 谢谢大家! targetListing是我的JSON对象Javascript 多维数组中的键值对搜索,javascript,arrays,json,Javascript,Arrays,Json,非常感谢您的阅读 我有一个JSON对象需要搜索,以确定是否存在值。我遇到的问题是查看一个数组,然后在功能数组中,测试是否存在“底层池” 谢谢大家! targetListing是我的JSON对象 var targetFeature = "In Ground Pool"; function valuateFeature(targetFeature){ for( var i = 0, len = targetListing.Features.length; i < len; i++ )
var targetFeature = "In Ground Pool";
function valuateFeature(targetFeature){
for( var i = 0, len = targetListing.Features.length; i < len; i++ ) {
if( targetListing.Features[i][0] === targetFeature ) {
return true
}else{
return false
}
};
} ;
查看
lodash.filter
var foundListings = _.filter(targetListing.Features, function() {
return this[0] === targetFeature
}
var found = foundListings.length > 0;
差不多吧。有几个lodash函数可能是合适的<代码>查找可能
我找到了:)
我需要在阵列中正确地瞄准目标
targetListing.Features[0]["Description"]
如果您发布JSON(使用jsonlint.com将其格式化)会更好。从你的问题中不可能分辨出数据的结构。原生javascript数组已经有了广泛支持的过滤方法。