Is there a smart way in Javascript to iterate over property names in objects in an array?
I have objects with several properties, including guest1 to guest100. In addition to the loop below, I would like to get another one that will loop over the guestx properties without writing down its long arm. This will be a very long list, if I need to write the code below for the [i] .guest100 results, it will be some ugly code.
for (var i = 0; i < results.length; i++) {
if (results[i].guest1 != "") {
Do something;
}
if (results[i].guest2 != "") {
Do something;
}
if (results[i].guest3 != "") {
Do something;
}
etcetera...
}
source
share