I'am trying to implement something like autocomplete, so I'am running the function when oninput event fires. Because I'am making a fetch request instead of running it on every change I'd like to run it not more than once in (maybe) 500ms. Is there a way to do this?
<body>
<input id="input" type="text">
<script>
function filterData(substr) {
fetch(url)
.then(response => response.json())
.then(data => {
let filteredData = data.filter(person => person.name.includes(substr));
print(filteredData);
})
}
document.getElementById("input").oninput = (e) => filterData(e.target.value);
</script>
</body>