0

I am trying to get the distinct value of array in Object. I find similar post but It cant solve me issue.

Output

enter image description here

In Airline there might be 1 or multiple values ( which might be repeated ) from API. How can I count the distinct value of Airline, Flight, Agent, Commodity_level_1 and Commodity_level_2

Update

enter image description here

Code

    Array.forEach(element => {
          let al = element.selectedData.airline.filter(
            (v, i, a) => a.indexOf(v) === i
          );
          console.log(al, " in the loop");
        });

Result

  • "AirArabia"
  • "Emirates"
  • "Turkish"
SternK
  • 11,649
  • 22
  • 32
  • 46
user12552117
  • 109
  • 2
  • 10
  • The below link is what you are looking for i suppose, You need to call the same method for all the fields, be it airlines, Flight, Agent etc. Let me know if it helps, or you can share a sample code. https://stackoverflow.com/questions/1960473/get-all-unique-values-in-a-javascript-array-remove-duplicates – TheViralGriffin Dec 19 '19 at 14:02
  • 2
    Does this answer your question? [Get all unique values in a JavaScript array (remove duplicates)](https://stackoverflow.com/questions/1960473/get-all-unique-values-in-a-javascript-array-remove-duplicates) – CMartins Dec 19 '19 at 14:04
  • `array.filter((v, i, a) => a.indexOf(v) === i)` as an answer in the topic @CarlosMartins said – Jacopo Sciampi Dec 19 '19 at 14:05

0 Answers0