Join two multidimensional JSONs in 1

0

I am consuming a hotel api, this one throws me a json from which I filter those 5 stars then the 4 stars and so on but at the end of doing the filters I want to join them all in a single JSON .

Followed by JSON :

0:
attributes:{hotel: "PLAY HOTEL", hotelDescription: "O Play Hotel é o
mais novo hotel de Águas Claras, …ação. É o hotel econômico mais
ousado do País.   ", hotelTaxes: Array(2), hotelAddress: "Rua Macaúba,
15 - Águas Claras - Brasilia", hotelNeighborhood: "Águas Claras",
…}

0:
attributes:{hotel: "MERCURE BRASÍLIA LÍDER",
hotelDescription:"",hotelTaxes:Array(2), hotelAddress: "Qd 5 - SHN BL
I, 1 - Asa Norte Brasilia",hotelNeighborhood: "Asa Norte", …}

I am using the following code but this simply brings me the last filter I need to join what I already had with what I just filtered.

/*Obtengo lo seleccionado*/
jQuery('#stars-results input[type=checkbox]').each(function() {
if (this.checked) {
    selected.push(jQuery(this).val());
}
});
/*recorro el JSON por cada opcion seleccionada*/
for (x = 0; x < selected.length; x++) {
var result = oJsonstar.filter(function(i, n) {
    return i.attributes.hotelStars === parseInt(selected[x]);
});
/*El resultado loo asigno a la variable de salida*/
Object.assign(resultJson, result);
};
/*Salida*/
return resultJson;
    
asked by gabriel anatoly rojas 04.06.2018 в 05:33
source

0 answers