Skip to content
Advertisement

If all strings match in array then show matched object in Javascript

I am getting back the following array below and would like to show all the matched objects based off the matched strings.

Returned Array: ["USA", "FRA", "GBR"]

Original Array:

JavaScript

My desired Output is to show the country that matches:

JavaScript

JS:

JavaScript

Advertisement

Answer

One method to achieve this is to use reduce with includes.

JavaScript
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement