How to Remove the Last Element from Array in jQuery?

We will be discussing the jQuery array to remove the last element with the help of an example. This article will provide you with a simple example of how to remove the last element from the array jQuery.

Let’s see both examples of how to remove the last key in the jQuery array.

Example 1 Remove Last Element from jQuery Array

<!DOCTYPE html>
<html>
<head>
   <title>How to Remove Last Element in Jquery Array?</title>
   <script src="https://code.jquery.com/jquery-1.12.4.js"></script>
</head>
<body>
<script type="text/javascript">
    var sites = [ "Thor", "Elvis", "LightYear", "The Blck Phone" ];
    sites.pop();
    console.log(sites);
</script>
</body>
</html>

Output

[“Thor”, “Elvis”, “LightYear”]

Example 2 Remove First Element from Array

<!DOCTYPE html>
<html>
<head>
   <title>How to Remove First Element from Jquery Array?</title>
   <script src="https://code.jquery.com/jquery-1.12.4.js"></script>
</head>
<body>
<script type="text/javascript">
    var sites = [ "Thor", "Elvis", "LightYear", "The Black Phone" ];
    sites.shift();
    console.log(sites);
</script>
</body>
</html>

Output

[“Elvis”, “LightYear”,”The Black Phone”]


Notice: ob_end_flush(): failed to send buffer of zlib output compression (1) in /home/u212091429/domains/mydevhelp.com/public_html/wp-includes/functions.php on line 5420

Notice: ob_end_flush(): failed to send buffer of zlib output compression (1) in /home/u212091429/domains/mydevhelp.com/public_html/wp-includes/functions.php on line 5420