Search code examples
jqueryjsonjquery-filter

How to filter the object what we want from json data..?


I am getting the response from backend, it return the json data.

But I need to pass the object separately to "handlebars.js" - templates.

In this case, how do I iterate the json response and filter the data what I want?

My sample data :

{
    "username":"xxxx",
    "name":"yyyyy",
    "allLocales":[
        {           "name":"Afrikaans"
        },
        {           "name":"Albanian"
        }           "name":"Arabic"

    ],
    "userLocales":[
        {           "name":"English (US)"
        },
        {           "name":"Swedish"
        }

],
    "message":"New massage will be here"
}

How can I get the var username = {"username":"xxxx"}, and

var nantions = "allLocales":[
            {           "name":"Afrikaans"
            },
            {           "name":"Albanian"
            }           "name":"Arabic"

        ]

and like so..?


Solution

  • You can use a method to easy parse your data.

    with hasOwnProperty

    Fiddle : JSFiddle example