I am trying to filter my objects from an array list based on the user input, but I am not sure how to achieve this.
That's my html:
<input id="search" type="text" placeholder="Search..">
<div id="animallist"></div>
javascript:
const animals = [{
name: "Cat",
useful: "no"
},
{
name: "Dog",
useful: "yes"
},
{
name: "Fish",
useful: "no"
}
]
animals.forEach(addLink);
function addLink(animal, i) {
const div = document.createElement('div');
const animalList = document.createElement('h2');
animalList.innerHTML = animal.name + " " +"-"+"useful?" + " "+ animal.useful;
animalList.style.cssText = "text-align:center;"
div.appendChild(animalList);
animallist.appendChild(div);
}
I dont know if that's possible, but I wanted to do it that way, so it would filter the items in real time, so If I would enter letter C in my search box, then it would eliminate 2 other items in the array list and showed only Cat.