I need help with this nested for loops with if statement. What i want to do is to show only this li's on site which are included in resultFlats
array of objects (resultFlats[i].id
).
Now its not working properly.
Getting number id from li and id from resultFlats
are working fine, but there is sth wrong with if statement
var arrayFlats = $('.search-my-house');
// e.g.
var resultFlats = [
{
name: "test",
id: "1"
},
{
name: "test2",
id: "4"
}
]
for (var j = 0; j < arrayFlats.length; j++) {
var number;
number = $(arrayFlats[j]).children('.apartment-number').text();
number = number.replace(/\s/g, "");
number = Number(number);
for (var i = 0; i < resultFlats.length; i++) {
var showId = Number(resultFlats[i].id)
if(showId === number) {
$(arrayFlats[j]).css('display', 'flex')
} else {
$(arrayFlats[j]).css('display', 'none')
}
};
};
<li class="search-my-house" data-loggia="" data-taras="1">
<div class="col description-small text-bold all-apartments apartment-number">22</div>
<div class="col description-small text-bold all-apartments levels">piętro 1</div>
<div class="col description-small text-bold all-apartments rooms">4</div>
<div class="col description-small text-bold all-apartments">168m<sup>2</sup></div>
<div class="col description-small text-bold all-apartments is-occupied">free</div>
<div class="col description-small">
<a href="wolne" class="button secondary">
<span>download</span>
</a>
</div>
</li>
<li class="search-my-house" data-loggia="" data-taras="1">
<div class="col description-small text-bold all-apartments apartment-number">1</div>
<div class="col description-small text-bold all-apartments levels">piętro 1</div>
<div class="col description-small text-bold all-apartments rooms">4</div>
<div class="col description-small text-bold all-apartments">168m<sup>2</sup></div>
<div class="col description-small text-bold all-apartments is-occupied">free</div>
<div class="col description-small">
<a href="wolne" class="button secondary">
<span>download</span>
</a>
</div>
</li>
<li class="search-my-house" data-loggia="" data-taras="1">
<div class="col description-small text-bold all-apartments apartment-number">184</div>
<div class="col description-small text-bold all-apartments levels">piętro 1</div>
<div class="col description-small text-bold all-apartments rooms">4</div>
<div class="col description-small text-bold all-apartments">168m<sup>2</sup></div>
<div class="col description-small text-bold all-apartments is-occupied">free</div>
<div class="col description-small">
<a href="wolne" class="button secondary">
<span>download</span>
</a>
</div>
</li>