HTML example code. This should remove the first element, and then you can return the remaining:
If you have an array, the shift function shifts everything to the left.
<!DOCTYPE html> <html> <body> <script> var arr = [1, 2, 3, 4]; var remEle = arr.shift(); // Removed Element == 1 console.log(remEle) console.log(arr); </script> </body> </html>
Another way, you could also use slice(1);
slice function doesn’t change the original Array.
var myarray = ["item 1", "item 2", "item 3", "item 4"]; alert(myarray.slice(1));
Do comment if you have any doubts and suggestions on this JS Array topic.
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.