Note: Pop() method will change the length of the array in JS.
HTML example code.
When you execute
pop() function even though the line returns the popped item the original array is affected and the popped element is removed.
<!DOCTYPE html> <html> <body> <script> var arr = [1,2,3,4]; var ele = console.log(arr.pop()); console.log(arr); console.log(ele); </script> </body> </html>
You can do it in two ways using
Do comment if you have any doubts or suggestions on this JS Array code.
Note: The All JS Examples codes are tested on the Firefox browser and the Chrome browser.
OS: Windows 10
Code: HTML 5 Version
Degree in Computer Science and Engineer: App Developer and has multiple Programming languages experience. Enthusiasm for technology & like learning technical.