How to Use Array Remove First Element using Node Js?
Jan 07, 2022 . Admin
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 :
Run following command to create node app.
mkdir my-app cd my-app npm initStep 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.jsOutput :
JavaScript [ 'lenovo', 'apple', 'hp' ]
Example 2 :
Step 1 : Create Node AppRun following command to create node app.
mkdir my-app cd my-app npm initStep 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.jsOutput :
[ 'javascript', 'php', 'jQuery' ]
It will help you...