How To Use Array Remove First Element Using Node Js?


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


Hello Friends,

This article will give you example of array remove first element in nodejs. I explained simply about remove first specific element from array in nodejs. This tutorial will give you simple example of Splice to Remove first 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 first items by value using splice. i will show you array filter method to remove first 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 first 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

var product = ['dell', 'lenovo', 'apple', 'hp']; 
var theRemovedElement = product.shift();

console.log(product);

now you can simply run by following command:

node server.js
Output :
JavaScript
[ 'lenovo', 'apple', 'hp' ]

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

const subjects = ['node js', 'javascript', 'php', 'jQuery'];
subjects.splice(0, 1);

console.log(subjects);

now you can simply run by following command:

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

It will help you...

Share: