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?

4
  • Can you show us your sel string? Commented Apr 4, 2016 at 7: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 Commented Apr 4, 2016 at 7: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 Commented Apr 4, 2016 at 7:13
  • in this thread is used the .each() method stackoverflow.com/questions/15219435/… Commented Apr 4, 2016 at 7:15

2 Answers 2

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;
}
Sign up to request clarification or add additional context in comments.

Comments

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.

}

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.