I'm working in some jQuery code and I've some doubts. This is what I've until now:
var html = '';
data.entities.forEach(function (value, index, array) {
html += index !== data.entities.length-1 ? value.pais + ', ' : value.pais;
});
var rowUpdate = $('#distribuidorBody').find('#td-' + data.idToUpdate);
rowUpdate.text() !== "" ? html += ', ' + html : html;
rowUpdate.append(html);
The big idea: I can execute the same code several times so the first time rowUpdate
doesn't have any values so text()
is empty and I will get some output in HTML as for example: Country1, Country2, Country3
and so on then rowUpdate.text()
should be Country1, Country2, Country3
. So if second time I ran the same code and add Country4, Country5
then rowUpdate.text()
should be Country1, Country2, Country3, Country4, Country5
. Is my code right? If not any help? I'm not getting errors but I need to understand if what I'm doing is right or wrong. Also I like to know what this code does:
rowUpdate.text() !== "" ?: html += ', ' + html;
It's not mine I see it around it but doesn't know what it does.