JSFiddle - React, Tailwind, and code Playground
by Karan1412
HTML
<p id="errorMessage"></p>
<p id="arrayElements"></p>
<p id="arrayLength"></p>
<input type="text" id="userInput" />
<input type="button" id="pushButton" Value="Push" />
CSS
#errorMessage {
color:Red;
}
JavaScript
var myArray = new Array();
myArray.push("Hello World");
var length = myArray.push("Cheers !!");
$("#arrayElements").text(myArray);
$("#arrayLength").text("Array Length : " + length);
$("#pushButton").click(function () {
var textToAdd = $("#userInput").val();
if (textToAdd != "") {
$("#errorMessage").text("");
var newLength = myArray.push(textToAdd);
$("#arrayElements").text(myArray);
$("#arrayLength").text("Array Length : " + newLength);
} else {
$("#errorMessage").text("Please enter valid input");
}
});