How to Remove First Element from Array in jQuery?

In this article, we will discuss how to remove the first element from the array jQuery with the help of an example.

You can see both examples with an output so that you are clear about how it works.

Example 1: 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”]

Example 2: 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 Black Phone" ];
  
    sites.pop();
  
    console.log(sites);
  
</script>
  
</body>
</html>
Output:

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