How to Concat Array in Node JS?
Hi friends,
I am going to explain you example of how to concat array in node js. I’m going to show you about add elements in array in node.js. I would like to show you concat elements in array in node js. I would like to share with you array using concate function in node js.
In this post, the example is how to concat array in node js. I will use the concat function merge array. This function used to two array merge one array in node js.
let's see below simple example with output:
Install Node JS
This step is not required; however, if you have not created the node js app, then you may go ahead and execute the below command:
mkdir my-app
cd my-app
npm init
Example:
You may also create a new array of the items you want to prepend to the existing array.
index.js
// create array list
myArray = ['One', 'Two', 'Three'];
// concat new element with value
newArray = myArray.concat(['Four', 'Five']);
console.log(newArray);
Output:
[ 'One', 'Two', 'Three', 'Four', 'Five' ]
It will help you...
- How to Install Node Js and NPM Ubuntu?
- How to used Google ReCaptcha V3 in Node Js Express?
- How to Send Email with Attachment in Node js?
- How to Insert Data from Form into MySQL Database using Node js Express?
- Install Node Js and NPM Ubuntu 18.04/20.04/22.04 Tutorial
- How to Delete Data by id into MongoDB in Node JS?
- Install Node.js 16/17/18 on CentOS 8 Tutorial
- How to Upload File in MongoDB using Node js Express?