SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    Jun 2010
    0 Post(s)
    0 Thread(s)

    How to iterate through table(Javascript)

    Help wanted.
    Consider a table having these values.

    01.07.2010 9hrs
    02.07.2010 9hrs
    04.07.2010 9hrs

    Now i need the dates that do not have hours. i.e on 03.07.2010 there are no hours in this table.But I need that date value. Basically i need to know which all dates do not have hours from this table. I need to know the dates that are not present in this table and the date can from 01.02.2010 and 30.02.2010. Can anyone please help me on this logic. I am not able to get a javascript logic to get the dates that do not have an entry in this table.

  2. #2
    SitePoint Enthusiast TriLLi's Avatar
    Join Date
    Feb 2010
    BiH, Bugojno
    0 Post(s)
    0 Thread(s)
    Hi, I will try to help you

    First of all you need strategy.

    1. Find all values in table
    2. generate all dates and put them into array
    3. go trough all values from table and check does value contain hrs and mark them properly.

    to check if value contain valid date you can use next regex

    now you can loop trough list of all dates and check if value exists in your array generated during looping trough rows of table

    Code JavaScript:
    var allDates;
    var generatedDates;
    for(var d in allDates)
        //code if date exists
        //code if date doesn't exists

  3. #3
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Sydney, NSW, Australia
    25 Post(s)
    1 Thread(s)
    for(var d in allDates)

    that implies that it is an associative array any you want all the properties and methods and not just the actual array entries. You should use a normal for or while loop to process an array where you don't want to process methods as well as properties.
    Stephen J Chapman, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts