1

This is how I get data inside jQuery:

    var jsonList = '[{"region":"NCA","depprt":"Havana, Cuba"},{"region":"NCA","depprt":"Havana, Cuba"}]';

  var jsList = JSON.parse(jsonList);
  var nesels = $.trim(sel);
  var ncaList = jsList.filter(function (obj) { return obj.region == nesels; });

In here ncaList provide filtered data. Now I want to get only depprt from the filtered data to the array without any duplicates. How can I do that?

bill
  • 854
  • 3
  • 17
  • 41
  • Can you show us your `sel` string? – urbz Apr 04 '16 at 07:07
  • 1
    You can use map get on `ncaList = ncaList.map(function(o){return o.depprt; })` then you can get unique value using various methods – Satpal Apr 04 '16 at 07:07
  • @Satpal ys it is working put this as an answer.I will vote.and at the same time how can I remove duplicate values – bill Apr 04 '16 at 07:13
  • in this thread is used the `.each()` method http://stackoverflow.com/questions/15219435/jquery-get-data-from-json-array – ralf htp Apr 04 '16 at 07:15

2 Answers2

1

You can use .map() to extract only depprt like

ncaList = ncaList.map(function(o){
     return o.depprt; 
}).filter(onlyUnique);

With reference to @TLindig answer

function onlyUnique(value, index, self) { 
    return self.indexOf(value) === index;
}
Community
  • 1
  • 1
Satpal
  • 132,252
  • 13
  • 159
  • 168
0

Supposing that "ncalist" is also in json format as jslist.

You can traverse and get required info/fields as :

for(i = 0; i < ncalist.length; i++){
 var depprtVar = ncalist[i]["depprt"];
    // here you can write code to check for duplication in your array and add the depprtVar to array if it is not in the array.

}
Pankaj Verma
  • 191
  • 10