I always want to delete the first index with each click of a button. How do I do?

0

Given what I've tried:

<html>

<body>
<script>
    var nome = ['1', '2', '3', '4', '5', '6', '7', '8', '9'];

    var remover = nome.slice(0);

    function shuffle(array) {
        return (Math.round(Math.random()) - 1);
        remover.splice(array, 1);
    }

    shuffle(nome);

    alert(nome);
</script>

</body>

</html>

But I did not know how to add a button for that purpose and still this code does not do the purpose.

    
asked by anonymous 18.03.2017 / 16:50

1 answer

3

Your code is a bit confusing and does not match what you ask for in the title, here is what you ask for in the title of the question:

var first_ele;
var btn = document.getElementById('btn');
var nome = ['1', '2', '3', '4', '5', '6', '7', '8', '9'];
btn.addEventListener('click', function() {
  first_ele = nome.shift();
  console.log(first_ele, nome)
});
<button id="btn">apagar primeiro ele</button>

With splice() farias:

...
first_ele = nome.splice(0, 1);
...
    
18.03.2017 / 16:56