How to Remove Last Element from Array in JQuery?

By Hardik Savani January 26, 2022 Category : jQuery

Hi Dev,

Today, jquery array remove last element is our main topic. this example will help you how to remove last element from array in jquery. This article will give you simple example of remove last element from array jquery. step by step explain jquery array remove last element. you will do the following things for remove last element from array jquery.

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

let's see example

You can see both example with output so, you can understand, how it works.

Example 1: Remove Last Element from Jquery Array

<!DOCTYPE html>

<html>

<head>

<title>How to Remove Last Element in Jquery Array? - ItSolutionStuff.com</title>

<script src="https://code.jquery.com/jquery-1.12.4.js"></script>

</head>

<body>

<script type="text/javascript">

var sites = [ "ItSolutionStuff.com", "HDTuto.com", "NiceSnippets.com", "Hackthestuff.com" ];

sites.pop();

console.log(sites);

</script>

</body>

</html>

Output:

["ItSolutionStuff.com", "HDTuto.com", "NiceSnippets.com"]

Example 2: Remove First Element from Array

<!DOCTYPE html>

<html>

<head>

<title>How to Remove First Element from Jquery Array? - ItSolutionStuff.com</title>

<script src="https://code.jquery.com/jquery-1.12.4.js"></script>

</head>

<body>

<script type="text/javascript">

var sites = [ "ItSolutionStuff.com", "HDTuto.com", "NiceSnippets.com", "Hackthestuff.com" ];

sites.shift();

console.log(sites);

</script>

</body>

</html>

Output:

["HDTuto.com", "NiceSnippets.com", "Hackthestuff.com"]

I hope it can help you...

Tags :
Shares