非常感谢您的阅读!多维数组搜索键值对
我有一个JSON对象,我需要通过搜索来查找是否有值。我遇到的问题是查看数组,然后在Feature数组内,以测试“In Ground Pool”是否存在。
谢谢!
targetListing是我的JSON对象
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
}
};
} ;
Address
:
Object
AgentEmail
:
"xxxxx"
AgentId
:
"xxxx"
AgentName
:
"Richard Getz"
AgentPhone
:
"xxxx"
AllListings
:
false
Bath
:
0
Bedroom
:
5
Brokerage
:
"xxxx"
BuildingStyle
:
"House"
BuildingStyleId
:
1
DaysPosted
:
0
Description
:
"If you've ever ..."
Features
:
Array[2]
0
:
Object
Description
:
"In Ground Pool"
__proto__
:
Object
1
:
Object
Description
:
"Attached Garage"
__proto__
:
Object
length
:
2
__proto__
:
Array[0]
HouseType
:
"Mediterranean"
HouseTypeId
:
3
Images
:
Array[0]
如果您发布了JSON(使用jsonlint.com进行良好格式化)会更好。从你的问题中分析数据的结构是不可能的。 – Barmar