I've a json array where I want to split it into 4 element sub arrays. I've written a loop to go through each element and create a dom element which I need to insert into the parent DOM element. but the function appends a set of parent elements whihc only contains one sub element to the document. Could any one help me on what wrong I'm doing.
jsonString.hotelDetails.forEach(function(elem){
var hotel = hotelModel.clone();
hotel.find('.location').html(elem.city);
hotel.find('.name').html(elem.hotelName);
hotel.find('.hotel-price').html(elem.currencyCode + " " + elem.adultRate);
hotelArray.push(hotel);
if(hotelArray.length == 4){
$('<div/>', { class: 'search-result-row'}).append(hotelArray).append('<div class="clear"></div>').appendTo('.search-result-container');
hotelArray = [];
}else if( (dataLength % 4) == hotelArray.length){
$('<div/>', { class: 'search-result-row'}).append(hotelArray).append('<div class="clear"></div>').appendTo('.search-result-container');
hotelArray = [];
}
});