How to Use Array Remove Last Element using Node Js?


Share:
 | Published By: Admin | Published On: Jan 06, 2022 | Category: Node JS


Hello Friends,

This article will give you example of array remove last element in nodejs. I explained simply about remove last specific element from array in nodejs. This tutorial will give you simple example of Splice to Remove last Array Elements. This is a short guide on use Removing Array Items By Value Using Splice in nodejs

In this post, you'll learn removing array last items by value using splice. i will show you array filter method to remove last items by value nodejs.we will use splice and filter method to removing array item.

Here i will give you many example how to use array remove last element using node js.

Example 1 :

Step 1 : Create Node App

Run following command to create node app.

mkdir my-app
cd my-app
 
npm init
Step 2 : Create server.js file

server.js

let subjects = ['laravel', 'php', 'node js', 'JavaScript'];
let popped = subjects.pop();

console.log(popped);

console.log(subjects);

now you can simply run by following command:

node server.js
Output :
JavaScript
[ 'laravel', 'php', 'node js' ]

Example 2 :

Step 1 : Create Node App

Run following command to create node app.

mkdir my-app
cd my-app
 
npm init
Step 2 : Create server.js file

server.js

var subjects = ['laravel','php','javascript','jQuery'];

console.log(subjects.splice(0,subjects.length-1));

now you can simply run by following command:

node server.js
Output :
[ 'laravel', 'php', 'javascript' ]

It will help you...

Share: