peterschussheim
10/13/2016 - 1:39 PM

push

push

const pets = ["Cat", "Dog"];
const wishlist = ["Hamster", "Bunny", "Grasshoppler"];

// var total = pets.concat(wishlist);

var applied = pets.push.apply(pets, wishlist);
applied
const input  = document.querySelector('#input');
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('');
}

push

This Gist was automatically created by Carbide, a free online programming environment.

You can view a live, interactive version of this Gist here.