The real estate house objects in my JavaScript array are as follows:
var json = {
'homes': [{
"home_id": "1",
"price": "925",
"sqft": "1100",
"num_of_beds": "2",
"num_of_baths": "2.0",
}, {
"home_id": "2",
"price": "1425",
"sqft": "1900",
"num_of_beds": "4",
"num_of_baths": "2.5",
},
// ... (more homes) ...
]
}
var xmlhttp = eval('(' + json + ')');
homes = xmlhttp.homes;
I want to be able to filter the object in order to get a selection of "home" items.
For instance, I'd want to be able to filter properties depending on price, sqft, number of bedrooms, and number of bathrooms.
How can I carry out the following pseudo-code in JavaScript:
var newArray = homes.filter(
price <= 1000 &
sqft >= 500 &
num_of_beds >=2 &
num_of_baths >= 2.5 );
Please take note that the syntax need not be precisely as stated above. This is only an illustration.