user1847371 user1847371 - 4 months ago 9
jQuery Question

How to get names list from json array using jquery?

I have json like

[
{
"name": "xx",
"address": "Ch"
},
{
"name": "yy",
"address": "Ch"
},
{
"name": "zz",
"address": "TRY"
}
]


I want result like

var names=["xx","yy","zz"]
But do not use looping.

Answer

You can use jsonQ http://ignitersworld.com/lab/jsonQ.html

var list=[
  {
    "name": "xx",
    "address": "Ch"
  },
  {
    "name": "yy",
    "address": "Ch"
  },
  {
    "name": "zz",
    "address": "TRY"
  }
];
var names=jsonQ(list).find("name").value();
Comments