How to Remove Last & First Element from Array Using JQuery?

Hello friends, today I will tell you through this tutorial how you can delete the first and last element with the help of jquery program. so let’s go

you can see both example of how to remove last key in jquery array.

Example 1: Remove Last Element from Array Using JQuery

In the example given below, you have been told how you can remove the last element with the help of jquery and its output is also given below.

<!DOCTYPE html>
<html>
<head>
<title>Remove Last Element in Jquery Array? - expertstool.com</title>
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
</head>
<body>
<script type="text/javascript">
var sites = [ "expertsphp.com", "expertstool.com", "expertstrick.com", "snaptwitter.com" ];
sites.pop();
console.log(sites);
</script>
</body>
</html>
["expertsphp.com", "expertstool.com", "expertstrick.com"]

Example 2: Remove First Element from Array Using JQuery

In the example given below, you have been told how you can remove the first element with the help of jquery and its output is also given below.

<!DOCTYPE html>
<html>
<head>
<title>Remove First Element from Jquery Array? - expertstool.com</title>
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
</head>
<body>
<script type="text/javascript">
var sites = [ "expertsphp.com", "expertstool.com", "expertstrick.com", "snaptwitter.com" ];
sites.shift();
console.log(sites);
</script>
</body>
</html>
["expertstool.com", "expertstrick.com", "snaptwitter.com"]

I hope it can help you…