SitePoint Sponsor

User Tag List

Results 1 to 2 of 2

Hybrid View

  1. #1
    SitePoint Enthusiast
    Join Date
    Apr 2011
    Posts
    65
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Exclamation urgent!!!how to show data with the same id?

    hi
    i recently working on a project
    i need to create hard code first of list of element
    something like the below of code but i not sure if i declare this array correctly?

    var it = [{ "id": "1001", "type": "Regular" },{ "id": "1002", "type": "Chocolate" },{ "id": "1002", "type": "Blueberry" },{ "id": "1004", "type": "Devil's Food" }]

    secondly, i want to show all the data that have same id..so how should do ?
    must i for loop and if loop...cause i know need to if loop....is it meaning using continue statement
    i need to show in when i click on a link and those with the same id will display in the dialog

    can show any example
    PS...reply asap!!!
    thanks!!!!!!

  2. #2
    SitePoint Addict AllanP's Avatar
    Join Date
    Sep 2010
    Location
    Australia
    Posts
    286
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Here is a simple JS script that shows each of the elments of the object array. Please note that I have changed your "id" to "idd" to avoid confusion.

    var it = [{ "idd":"1001", "type":"Regular" },{ "idd":"1002", "type":"Chocolate" },{ "idd":"1002", "type":"Blueberry" },{ "idd":"1004", "type":"Devil's Food" }]
    for(var i=0;i<it.length;i++)
    { alert(it[i].idd)}


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
  •