Page 239 - Web_Application_v2.0_C12_Fb
P. 239

Example 46: To demonstrate the use of toString() method

                    <!DOCTYPE HTML>
                    <HTML>
                    <HEAD>

                    <TITLE>ToString Array Method</TITLE>
                    </HEAD>
                    <BODY>
                    <H2>The toString() Method</H2>
                    <P>The toString() method converts an array into a string.</P>

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

                    </SCRIPT>
                    </BODY>
                    </HTML>
                 Output:



















                 2.   The pop() Method: The pop() method removes the last element in an array and returns it. This modifies
                    the original array, reducing its length by one.
                 Example 47: To demonstrate the use of pop() method

                    <!DOCTYPE HTML>
                    <HTML>

                    <HEAD>
                    <TITLE>Pop Array Method</TITLE>
                    </HEAD>
                    <BODY>

                    <H2>The pop() Method</H2>
                    <P>Original Array: </P>
                    <P id="demo1"></P>
                    <P>Pop Element: </P>

                    <P id="demo2"></P>
                                                                                                  JavaScript Part 2  237
   234   235   236   237   238   239   240   241   242   243   244