How to Filter a complex json object using javascript? How to Filter a complex json object using javascript? json json

How to Filter a complex json object using javascript?


You can use Array#filter and assign the result directly to the property HOMES.

var json = { "Lofts": "none", "Maisons": "2", "HOMES": [{ "home_id": "1", "price": "925", "num_of_beds": "2" }, { "home_id": "2", "price": "1425", "num_of_beds": "4", }, { "home_id": "3", "price": "333", "num_of_beds": "5", }] };json.HOMES = json.HOMES.filter(function (a) {    return a.home_id === '2';});document.write('<pre>' + JSON.stringify(json, 0, 4) + '</pre>');