how to get specific object value inside jquery from json string

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?

Answers 1

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

    ncaList ={
         return o.depprt; 

    With reference to @TLindig answer

    function onlyUnique(value, index, self) { 
        return self.indexOf(value) === index;

Related Articles