Here are the common ways to remove the first element from an array:

Using shift()

<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<meta name="viewport" content="width=device-width, initial-scale=1">
	<title>How to Remove First Element from Array in JavaScript?</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.shift();

	console.log(cityArray);
</script>
</body>
</html>

Output:

[ "Bhopal", "Bangalore", "Mumbai", "Chennai" ]

Description: 

  • Removes the first element
  • Modifies the original array

Using splice()

<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<meta name="viewport" content="width=device-width, initial-scale=1">
	<title>How to Remove First Element from Array in JavaScript?</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.splice(0, 1);

	console.log(cityArray);
</script>
</body>
</html>

Output:

[ "Bhopal", "Bangalore", "Mumbai", "Chennai" ]

Description:

  • Removes 1 element starting from index 0
  • Modifies the original array

Using slice()

<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<meta name="viewport" content="width=device-width, initial-scale=1">
	<title>How to Remove First Element from Array in JavaScript?</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"];

	var newCityArray = cityArray.slice(1);

	console.log(newCityArray);
</script>
</body>
</html>

Output:

[ "Bhopal", "Bangalore", "Mumbai", "Chennai" ]

Description:

  • Does NOT change the original array
  • Returns a new array starting from index 1

Summary

  • shift(): simplest way to remove first element
  • slice(1):  keeps original array unchanged
  • splice(0,1): flexible removal method