Javascript Remove First & Last Element in Array

Hello devs, today I'll show you how to remove first and last element of an array. We'll use two array method of called pop() and shift(). pop() basically removes the last element of an array and on the other hand shift removes the first element of an array. Let's see two examples of this method.

Example 1

<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Remove First & Last Element of an Array - shouts.dev</title>
</head>
<body>


<script>
    var stacks = [ "PHP", "Python", "Javascript", "ASP .Net" ];

    stacks.pop();

    console.log(stacks);
</script>
</body>
</html>
Removing Last Element in Array

Example 2

<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Remove First & Last Element of an Array - shouts.dev</title>
</head>
<body>


<script>
    var stacks = [ "PHP", "Python", "Javascript", "ASP .Net" ];

    stacks.shift();

    console.log(stacks);
</script>
</body>
</html>
Removing first Element in Array

That's it for today. Hope you've enjoyed this tutorial. Catch me in the comment section if anything goes wrong. Thanks for reading.