SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    Jun 2010
    Posts
    12
    Mentioned
    0 Post(s)
    Tagged
    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
    Location
    BiH, Bugojno
    Posts
    86
    Mentioned
    0 Post(s)
    Tagged
    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.

    Example:
    to check if value contain valid date you can use next regex
    ([0-9]{0,2})\.([0-9]{0,2})\.([0-9]{0,4})(\s){0,1}([0-9]hrs)

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

    Example:
    Code JavaScript:
    var allDates;
    var generatedDates;
     
    for(var d in allDates)
    {
      if(generatedDates[d])
        //code if date exists
       else
        //code if date doesn't exists
    }

  3. #3
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,870
    Mentioned
    25 Post(s)
    Tagged
    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

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">


Bookmarks

Posting Permissions

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