Skip to main content

javascript filter Array of objects

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

Popular posts from this blog

దోసకాయ పూర్ణం | cucumber curry

How to merge Objects in Javascript

 let person = {     firstName: 'Rocky',     lastName: 'g',     age: 23 }; let job = {     jobTitle: 'Angular Developer',     location: 'UK' }; let employee = {     ...person,     ...job }; console.log(employee);

క్యారెట్ ఊరగాయ | carrot pickle