-1

I currently have two arrays formatted as below:

   FreeChampions [
  15,
  17,
  21,
  27,
  37,
  45,
  61,
  72,
  78,
  89,
  92,
  99,
  102,
  121,
  142
]

and

 ChampionList [
  [
    "266",
    "Aatrox",
    "Aatrox"
  ],
  [
    "103",
    "Ahri",
    "Ahri"
  ],
  [
    "84",
    "Akali",
    "Akali"
  ],
  [
    "12",
    "Alistar",
    "Alistar"
  ],
  [
    "32",
    "Amumu",
    "Amumu"
  ],
  [
    "34",
    "Anivia",
    "Anivia"
  ],
  [
    "1",
    "Annie",
    "Annie"
  ],

I want to use the values of the FreeChampions Array to extract the object with the same value in the ChampionList array.

and then store those values in a new array.

tedsamaha
  • 19
  • 3

1 Answers1

0

This line should give you what you need. The filter filters out any elements who do not satisfy the find condition of the element being included in the FreeChampions array. Due to the type mismatch the y value needs to be cast to int for the includes to return truthy. Note that this will only work if the positions of the fields are static, ie the number in the inner array of ChampionsList is always at position 0.

var foundItems = ChampionList.filter(x => x.find(y => FreeChampions.includes(parseInt(y, 10))));
tuckerjt07
  • 902
  • 1
  • 12
  • 31