hello guys,
i'm still reading j pollocks book and i'm on the part of the pop() method. and i'm a bit confused about the pop() method because it's giving me two different results but with the same method. i know it's a bit confusing explaining but here's the code i tested.
the first script is from w3schools.com:
The result of fruit will be: Banana,Orange,Apple
the second script with pop() method also has a different result. it only gave the result of Mango. this is the same result as with the book that it only write the last item in the array not remove it. but in the first script from w3schools. the pop() method result was it removed the last array and displayed the remaining fruits. i don't understand which is whichCode:<body> <h2>pop() Method version 1</h2> <p id="demo">Click the button to remove the last array element.</p> <button onclick="myFunction()">Try it</button><br><br> <script type="text/javascript"> var fruits = ["Banana", "Orange", "Apple", "Mango"]; function myFunction() { fruits.pop(); var x = document.getElementById("demo"); x.innerHTML = "Result of pop method version 1: " + fruits; } </script> <h2>pop() Method version 2</h2> <script type="text/javascript"> var fruits2 = ["Banana", "Orange", "Apple", "Mango"]; var pickedFruit = fruits2.pop(); document.write("Result of pop method version 2: " + pickedFruit); </script> </body>? is this right i'm doing?
many thanks in advance.


? is this right i'm doing?
Reply With Quote


Bookmarks