Skip to content

Instantly share code, notes, and snippets.

@desoga10 desoga10/script.js

Last active Jun 8, 2019
Embed
What would you like to do?
//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
You can’t perform that action at this time.