Tuesday, January 1, 2013

Get unique values from json using jquery

Get Unique values
Hi..In this article i would like to share a simple logic to get unqiue values from json array using jquery.. Normally we are using jquery ajax in order to bind the data.In some cases, we need to bind unqiue records from json file. Here i would like to share two logics.First logic is the way to bind the data and another one is ,to bind the unique records

Consider Following is the example file of JSON.

[

        {
            "category": "Movie",
            "type": "English"
        },

        {
            "category": "Movie",
            "type": "Hindi"
        },
        {
            "category": "Movie",
            "type": "teulgu"
        },
        {
            "category": "games",
            "type": "Cricket"
        },
        {
            "category": "games",
            "type": "chess"

        },
        {
            "category": "games",
            "type": "Cricket"
        },
        {
            "category": "games",
            "type": "chess"

        },
        {
            "category": "hobbies",
            "type": "chating"
        },
        {
            "category": "hobbies",
            "type": "singing"
        },
        {
            "category": "hobbies",
            "type": "chating"
        },
        {
            "category": "hobbies",
            "type": "singing"
        }

  ]

Save this file as mydata.js.. Next write the following logic in between the script tags Here is the logic

Display Unique Records

Before Logic
After Logic
That's it..Following is the output you will get

Labels: , , , , , ,