<input type="button" id="button1" value="В начало" onclick="push1()">
<input type="button" id="button2" value="В конец" onclick="push2()"><br><br>
<input type="text" id="text" placeholder="Добавьте текст" onkeyup="pressAfterText()">
<p id="array"></p>
function pressAfterText(e) {
e = e || window.event;
if (e.keyCode === 13) {
document.getElementById("button1").click();
document.getElementById("button2").click();
}
return false;
}
var element = document.getElementById('array'),
text = document.getElementById('text'),
textValue = text.value;
var arr = ["Apple", "Samsung", "Huawei"];
element.textContent = arr;
function push1() {
textValue = text.value;
arr.unshift(textValue);
element.textContent = arr.join();
console.log(arr);
}
function push2() {
textValue = text.value;
arr.push(textValue);
element.textContent = arr.join();
}