geojson array filter with jquery

 I want to filter the below json array.


condition:  properties.name == "Abandoned Cars"

before  sample.json:
{
   "type":"FeatureCollection",
   "features":[
      {
         "type":"Feature",
         "geometry":{
            "type":"Point",
            "coordinates":[
               50.8212596,
               6.8961028
            ]
         },
         "properties":{
            "name":"Litter Basket Complaint",
            "description":"",
            "created":"08\/01\/2014 - 14:24",
            "field_status_hex":"cc0000",
            "field_category_hex":"5F9EA0",
            "field_address":"Pingsdorfer Stra\u00dfe 88, 50321 Br\u00fchl",
            "path":"\/spot\/reports\/2b8f-1",
            "field_status_icon":"pause",
            "field_category_icon":"trash",
            "nid":1
         }
      },
      {
         "type":"Feature",
         "geometry":{
            "type":"Point",
            "coordinates":[
               50.818128126776,
               6.8905774494293
            ]
         },
         "properties":{
            "name":"Graffiti Report",
            "description":"",
            "created":"08\/01\/2014 - 14:24",
            "field_status_hex":"cc0000",
            "field_category_hex":"8B0000",
            "field_address":"Am Ringofen 21, 50321 Br\u00fchl",
            "path":"\/spot\/reports\/d087-2",
            "field_status_icon":"pause",
            "field_category_icon":"graffiti",
            "nid":2
         }
      },
      {
         "type":"Feature",
         "geometry":{
            "type":"Point",
            "coordinates":[
               50.824350198819,
               6.8955127140167
            ]
         },
         "properties":{
            "name":"Abandoned Cars",
            "description":"",
            "created":"08\/01\/2014 - 14:24",
            "field_status_hex":"5F9EA0",
            "field_category_hex":"00008B",
            "field_address":"Liblarer Stra\u00dfe 88, 50321, Br\u00fchl",
            "path":"\/spot\/reports\/f0b4-3",
            "field_status_icon":"drawer",
            "field_category_icon":"car",
            "nid":3
         }
      },
      {
         "type":"Feature",
         "geometry":{
            "type":"Point",
            "coordinates":[
               50.828213159666,
               6.9081941982391
            ]
         },
         "properties":{
            "name":"Building Construction Complaint",
            "description":"",
            "created":"08\/01\/2014 - 14:24",
            "field_status_hex":"ff6600",
            "field_category_hex":6400,
            "field_address":"Promenade, 50321 Br\u00fchl",
            "path":"\/spot\/reports\/0dd0-4",
            "field_status_icon":"play",
            "field_category_icon":"office",
            "nid":4
         }
      },
      {
         "type":"Feature",
         "geometry":{
            "type":"Point",
            "coordinates":[
               50.8327211,
               6.9032226
            ]
         },
         "properties":{
            "name":"Abandoned Cars",
            "description":"",
            "created":"08\/01\/2014 - 14:24",
            "field_status_hex":"5F9EA0",
            "field_category_hex":"00008B",
            "field_address":"Friedrichstra\u00dfe 23 50321 Br\u00fchl",
            "path":"\/spot\/reports\/0a43-5",
            "field_status_icon":"drawer",
            "field_category_icon":"car",
            "nid":5
         }
      },
      {
         "type":"Feature",
         "geometry":{
            "type":"Point",
            "coordinates":[
               50.826873,
               6.900167
            ]
         },
         "properties":{
            "name":"Litter Basket Complaint",
            "description":"",
            "created":"08\/01\/2014 - 14:24",
            "field_status_hex":"5F9EA0",
            "field_category_hex":"5F9EA0",
            "field_address":"Centre, 50321 Br\u00fchl",
            "path":"\/spot\/reports\/d294-6",
            "field_status_icon":"drawer",
            "field_category_icon":"trash",
            "nid":6
         }
      }
   ]
}

Open in new window


After sample.json:
{
   "type":"FeatureCollection",
   "features":[
      {
         "type":"Feature",
         "geometry":{
            "type":"Point",
            "coordinates":[
               50.824350198819,
               6.8955127140167
            ]
         },
         "properties":{
            "name":"Abandoned Cars",
            "description":"",
            "created":"08\/01\/2014 - 14:24",
            "field_status_hex":"5F9EA0",
            "field_category_hex":"00008B",
            "field_address":"Liblarer Stra\u00dfe 88, 50321, Br\u00fchl",
            "path":"\/spot\/reports\/f0b4-3",
            "field_status_icon":"drawer",
            "field_category_icon":"car",
            "nid":3
         }
      },
         
      {
         "type":"Feature",
         "geometry":{
            "type":"Point",
            "coordinates":[
               50.8327211,
               6.9032226
            ]
         },
         "properties":{
            "name":"Abandoned Cars",
            "description":"",
            "created":"08\/01\/2014 - 14:24",
            "field_status_hex":"5F9EA0",
            "field_category_hex":"00008B",
            "field_address":"Friedrichstra\u00dfe 23 50321 Br\u00fchl",
            "path":"\/spot\/reports\/0a43-5",
            "field_status_icon":"drawer",
            "field_category_icon":"car",
            "nid":5
         }
      },
     
   ]
}

Open in new window


How to achieve After sample.json  result using jquery?

my expected code:
 $.getJSON(sample.json).done(function (data) {
$.each(data.features, function (markers, item) {
var returnedData = $.grep(item.properties, function(element, index){
          return element.name == "Abandoned Cars";
    });
// actually i dont how to do after this
document,write(returnedData.description[0]);
docment.write(returnedData.created[0]();
.
.
.
.
.

}
   

Open in new window

chrisveeAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

mankowitzCommented:
Try

var new_one = orig.features.filter(function(item) {
   return item.properties.name == "Abandoned Cars"
});

see http://jsfiddle.net/64MF4/
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
chrisveeAuthor Commented:
@mankowitz   Great!   I can see the filtered results in html. but can you please  assign the output to a js variable. like (var orig) . so that i can access filtered results from js variable
0
mankowitzCommented:
new_one is a json variable.
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

chrisveeAuthor Commented:
i mean  if  i          document.write(new_one);      it has to show array format like orig
0
chrisveeAuthor Commented:
Sorry. I understood now. I am just a noob in javascript. thanks for the solution
0
mankowitzCommented:
ohh.. I see what you are saying.

Try this instead

orig.features = orig.features.filter(function(item) {
   return item.properties.name == "Abandoned Cars"
});

and then you should be able to use orig.features[0].properties.name
0
chrisveeAuthor Commented:
Thanks for your answer. please clarify this doubt also.
http://jsfiddle.net/64MF4/

for Orig ,            the array starts with  "type":"FeatureCollection"
for new_one,     the array starts with  "type":"Feature",

But i want    new_one   same as Orig array format.  
Please help!
0
mankowitzCommented:
I think I answered this, but you can just do this:

orig.features = orig.features.filter(function(item) {
   return item.properties.name == "Abandoned Cars"
});
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.