Javascript looping only through defined properties of array. How?
Posted
by Beck
on Stack Overflow
See other posts from Stack Overflow
or by Beck
Published on 2010-06-12T13:47:17Z
Indexed on
2010/06/12
13:52 UTC
Read the original article
Hit count: 175
JavaScript
|loops
For example if i'm keeping array of references via id like that:
if(typeof channel_boards[misc.channel_id] == 'undefined') {
channel_boards[misc.channel_id] = $('<div class="channel" channel_id="'+misc.channel_id+'"></div>').appendTo('#board');
}
And then i'm looping through array to find required reference. I'm looping through undefined properties as well. Is it possible to loop only through defined properties?
for(i=0;i<channel_boards.length;i++)
{
if(channel_boards[i] != undefined)
{
if(channel_boards[i].attr('channel_id') != visible) {channel_boards[i].addClass('hidden_board');}
else {channel_boards[i].removeClass('hidden_board');}
}
}
Maybe i should change the way i'm storing references? Via object for example, but how i'll be able to find proper reference via id number.
© Stack Overflow or respective owner