how to make autocomplete functionality using JavaScript.
I'm trying to make autocomplete in appended input.

HTML code:

```
<input type="text" placeholder="Search Country.." id="data" onkeyup="getValue(this.value)" style="width:150px;padding:5px">
<div class="output"></div>

```

JavaScript code:

```
<script type="text/javascript">
    var result = document.querySelector('.output');
    var ddata = document.querySelector('#data');
    var Arr = ['India', 'USA','China','Netherlands','Nepal','Japan','Australia']

    function autoComplete(Arr, val) {
        return Arr.filter(e => e.toLowerCase().includes(val.toLowerCase()));
    }
    function getValue(val){
        if(!val){
            result.innerHTML='';
            return
        }
        var data = autoComplete(Arr,val);    
        for (var i = 0; i < data.length; i++) {
            ddata.value = data[i];
        }
    }
</script>

```