Page 245 - Web_Application_v2.0_C12_Fb
P. 245

Output:
























                 8.  The slice() Method: The slice() method returns a shallow copy of a portion of an array into a new array
                    object. The original array is not modified.

                 Example 53: To demonstrate the use of slice() method

                    <!DOCTYPE HTML>
                    <HTML>
                    <HEAD>
                    <TITLE>slice Array Method</TITLE>
                    </HEAD>

                    <BODY>
                    <H2>The slice() Method</H2>
                    <P>Original Array: </P>

                    <P id="demo1"></P>
                    <P>Array after using slice method: </P>
                    <P id="demo2"></P>
                    <SCRIPT>
                    const Fruits = ['Apple', 'Mango', 'Banana', 'Papaya'];

                    document.getElementById("demo1").innerHTML = Fruits;
                    document.getElementById("demo2").innerHTML = Fruits.slice(1, 3);
                    </SCRIPT>
                    </BODY>

                    </HTML>
                 Output:














                                                                                                  JavaScript Part 2  243
   240   241   242   243   244   245   246   247   248   249   250