Skip to content

Instantly share code, notes, and snippets.

@desoga10
Last active June 8, 2019 17:14
Show Gist options
  • Save desoga10/ab76d82310dc2bd149d4137d535f6e63 to your computer and use it in GitHub Desktop.
Save desoga10/ab76d82310dc2bd149d4137d535f6e63 to your computer and use it in GitHub Desktop.
//Get Countries From Json File
const searchcountry = async searchBox => {
const res = await fetch('../data/countries.json');
const countries = await res.json();
//Get & Filter Through Entered Data
let fits = countries.filter(country => {
const regex = new RegExp(`^${searchBox}`, 'gi');
return country.name.match(regex) || country.abbr.match(regex);
});
//Clears Data If Search Input Field Is Empty
if (searchBox.length === 0) {
fits = [];
countryList.innerHTML = '';
}
outputHtml(fits);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment