Last active
June 8, 2019 17:14
-
-
Save desoga10/ab76d82310dc2bd149d4137d535f6e63 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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