JSFiddle - React, Tailwind, and code Playground
HTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script src="unshift.js"></script>
</head>
<body onload="tnwFun1();">
<p id="demo"></p>
<p id="demo1"></p>
<input type="text" name="newname" id="newname" placeholder="Type here...">
<button type="button" onclick="tnwFun2()">Add new names</button>
</body>
</html>
CSS
button{
cursor: pointer;
}
JavaScript
const tnwNames = ["Moe", "Soe", "Noe", "Mya"];
function tnwFun1(){
document.getElementById("demo").innerHTML = tnwNames.join(", ");
}
function tnwFun2(){
document.getElementById("demo").innerHTML = "The original array is " + tnwNames.join(", ");
let tnwNewvalue = document.getElementById("newname").value;
tnwNames.unshift(tnwNewvalue);
document.getElementById("demo1").innerHTML = "The new array is " + tnwNames.join(", ");
}