Description: filtering the array with the conditions return into the new Array
Ex:
var obj = {
'homes': [{
"home_id": "1",
"price": "120",
"sqft": "100",
"beds": "3",
"baths": "2.0",
}, {
"home_id": "2",
"price": "1425",
"sqft": "100", "beds": "2",
"baths": "2.0",
}
]
};
var newArray = obj.homes.filter(function (el) {
return el.price <= 1000 &&
el.sqft >= 500 &&
el.num_of_beds >= 2 &&
el.num_of_baths >= 2
});
console.log(newArray);
Output
[
{
"home_id": "1",
"price": "120",
"sqft": "100",
"beds": "3",
"baths": "2.0"
}
]
Comments
Post a Comment