array push

by james gotsell

HTML

<script src="https://getfirebug.com/firebug-lite.js"></script>
    <input type="text" id="input">

    <button type="button" id="button">Add</button>

    <ul id="list">
        <!-- Pets -->
    </ul>

Babel + JSX

const animals = ['dog','cat','bird']
const wishList = ['fish', 'stuff']
animals.push.apply(animals, wishList);
// using push is a destructive update 

console.log(animals)

const button = document.querySelector('#button');
const list   = document.querySelector('#list');

const pets   = [];

button.addEventListener("click", function (evt) {
    if (input.value.length > 0) {
        pets.push(input.value);
        input.value = "";
        render();
    }
});

function render () {
    list.innerHTML = pets.map(x => `<li>${x}</li>`).join('');
}

console.log(pets)