I have a situation where I created an array of objects and implemented a function to loop through this array, generating HTML elements and populating them with values from the objects. These elements are appended to existing HTML tags on the page. Currently, the result is a list displayed on the webpage. However, I am seeking assistance in utilizing user input to filter through the array of objects. I want to display only the values that match the user's input. Can anyone provide guidance or help?
let internationalCountries = [
{
name: "Spain",
method: "Delivery",
price: "£10.99",
},
{
name: "Germany",
method: "Delivery",
price: "£8.99",
},
{
name: "Japan",
method: "Delivery",
price: "£39.99",
},
]
let renderCountryList = () => {
let list;
let itemName = "";
let para1;
let para2;
let method = "";
let price = "";
let ul = document.querySelector('.country-list')
let deliveryInfo = document.querySelector('.delivery-info')
for (let i = 0; i < internationalCountries.length; i++){
list = document.createElement('li')
itemName = document.createTextNode(internationalCountries[i].name)
list.appendChild(itemName)
ul.appendChild(list)
para1 = document.createElement('p')
para2 = document.createElement('p')
method = document.createTextNode(internationalCountries[i].method)
price = document.createTextNode(internationalCountries[i].price)
para1.appendChild(method)
para2.appendChild(price)
deliveryInfo.appendChild(para1)
deliveryInfo.appendChild(para2)
}
}
renderCountryList()
<input type="text" placeholder="Search..." id="searchInput">
<div>
<ul class="country-list">
</ul>
</div>
<div class="delivery-info">
</div>