How To Append Value To An Array In JavaScript

How To Add Value To An Array Using Javascript

Add Element To An Array Using JavaScript

In This Javascript Tutorial we will see How To Add Element To An Array From Input Text Field Using Push Method Array In JS Using Netbeans Editor .

Project Source Code:

<!DOCTYPE html>

        <title>TODO supply a title</title>
        <meta charset="windows-1252">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <input type="text" name="text" id="inputText"/>
        <button onclick="pushData();">Show</button>
        <p id="pText"></p>
            // create an array
            var myArr = ["A","B","C","D"];
            function pushData()
                // get value from the input text
                var inputText = document.getElementById('inputText').value;
                // append data to the array
                var pval = "";
                for(i = 0; i < myArr.length; i++)
                    pval = pval + myArr[i] + "<br/>";
                // display array data
                document.getElementById('pText').innerHTML = pval;