Here are the common ways to remove elements from an array in jQuery/JavaScript:
Remove Last Element (pop())
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>How to Remove Last Element or Remove by Value from Array in jQuery?</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.7.1/jquery.min.js"></script>
</head>
<body>
<script>
var cityArray = ["Patna", "Bhopal", "Bangalore", "Mumbai", "Chennai"];
cityArray.pop();
console.log(cityArray);
</script>
</body>
</html>
Output:
[ "Patna", "Bhopal", "Bangalore", "Mumbai" ]

Description:
- Removes the last element from the array
- Modifies the original array
- Returns the element that was removed
Remove Element by Value
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>How to Remove Last Element or Remove by Value from Array in jQuery?</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.7.1/jquery.min.js"></script>
</head>
<body>
<script>
var cityArray = ["Patna", "Bhopal", "Bangalore", "Mumbai", "Chennai"];
cityArray = cityArray.filter(function(item) {
return item !== "Bangalore";
});
console.log(cityArray);
</script>
</body>
</html>
Output:
[ "Patna", "Bhopal", "Mumbai", "Chennai" ]

Description:
- Removes elements that match a specific value
- Returns a new array instead of modifying the original one directly
- The original array remains unchanged unless it is reassigned with the result
Remove Element by Index (splice())
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>How to Remove Last Element or Remove by Value from Array in jQuery?</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.7.1/jquery.min.js"></script>
</head>
<body>
<script>
var cityArray = ["Patna", "Bhopal", "Bangalore", "Mumbai", "Chennai"];
// Remove element at index 3 (Mumbai)
cityArray.splice(3, 1);
console.log(cityArray);
</script>
</body>
</html>
Output:
[ "Patna", "Bhopal", "Bangalore", "Chennai" ]

Description:
- The first number represents the starting index position
- The second number specifies how many items to remove
- It modifies the original array directly
Summary
shift(): removes the first elementpop(): removes the last elementsplice(index, 1):removes an element at a specific indexfilter():removes elements based on a condition (recommended for conditional removal)