How to Remove Last Element of Array in Node JS?

25-Jul-2022

.

Admin

Hello Friends,

This tutorial is focused on how to remove the last element of an array in Node Js?. we will help you to give an example of Node Js remove the last element of the array. if you want to see an example of node.js remove the item for the array then you are in the right place. This article will give you a simple example of remove the item from the list in Node Js.

In this example, I will give you two examples. one using "splice" in node.js and another using "pop" function of array. it will remove last element from array in Node Js.

let's see below simple example with output:

Example: 1


index.js

myArray = ['sun','mon','tus','wen','thi','fri','sat']

myArray.pop();

console.log(myArray);

Output:

['sun','mon','tus','wen','thi','fri']

Example: 2

index.js

arr = ['sun','mon','tus','wen','thi','fri','sat']

arr.splice(-1,1);

console.log(arr);

Output:

['sun','mon','tus','wen','thi','fri']

I hope it can help you...

#Node JS