How to build an array from a jSon object
If j
is your json:
var a1 = [];
var a2 = [];
$.each( j, function( key, ob ) {
if(ob.price > 100 && ob.status == 'available'){
a1.push(key);
}
if(ob.status == 'booked' || ob.status == 'unavailable'){
a2.push(key);
}
});
console.log(a1);
console.log(a2);
Yields:
["2015-03-24", "2015-03-25", "2015-03-26"]
["2015-04-10", "2015-04-11", "2015-05-01", "2015-05-02", "2015-05-03"]