How to Use Array Map using Node Js?


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


Hello Friends,

This article will give you example of node js array map example. I explained simply about node js convert array to map. This tutorial will give you simple example of node js create map from array. This is a short guide on use node js array map function in nodejs

In this post, you'll learn how to use array map function in node js. i will show you javascript array map() method. we will use array map function given below.

Here i will give you many example of how to use array map function in 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

const temp = [1, 5, 3, 12];

const temp2 = temp.map(x => x * 2);

console.log(temp2);

now you can simply run by following command:

node server.js
Output :
[ 2, 10, 6, 24 ]

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

let temp = [1, 4, 6]

let dblNum = temp.map(function(num) {
  	return num * 2
})

console.log(dblNum);

now you can simply run by following command:

node server.js
Output :
[ 2, 8, 12 ]

It will help you...

Share: