Page 240 - Web_Application_v2.0_C12_Fb
P. 240

<P>Array after using Pop method: </P>
                  <P id="demo3"></P>

                  <SCRIPT>
                  const Fruits = ['Apple', 'Mango', 'Banana', 'Papaya'];
                  document.getElementById("demo1").innerHTML = Fruits;

                  document.getElementById("demo2").innerHTML = Fruits.pop();
                  document.getElementById("demo3").innerHTML = Fruits;
                  </SCRIPT>
                  </BODY>
                  </HTML>
              Output:



























              3.  The push() Method: The push() method adds one or more new elements to the end of an array. It
                 returns the new length of the array after the element is added.

              Example 48: To demonstrate the use of push() method

                  <!DOCTYPE HTML>
                  <HTML>
                  <HEAD>

                  <TITLE>push Array Method</TITLE>
                  </HEAD>
                  <BODY>
                  <H2>The push() Method</H2>
                  <P>Original Array: </P>

                  <P id="demo1"></P>
                  <P>Push Element: </P>
                  <P id="demo2"></P>
                  <P>Array after using push method: </P>

                  <P id="demo3"></P>

                238   Touchpad Web Applications (Ver. 2.0)-XII
   235   236   237   238   239   240   241   242   243   244   245