Node JS Convert Array to String Example

09-Aug-2022

.

Admin

Node JS Convert Array to String Example

Hi Friends,

Today, node js convert array to string example is our main topic. you'll learn node.js convert array to string. We will use an array-to-string example in node js. you will learn to convert array to string using join(). Follow the below tutorial step of node.js array to string using toString().

There are many ways to use convert array to string in node js. I will give you two examples using toString() and join(). Using the toString() method on an array will return a string representation of the array list. we will use the join() method of an array to return a concatenation of the array elements.

let's see below a 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: 1

index.js

//create an array list

myArray = [1, 2, 3, 4]

//convert array to string

myString = myArray.toString()

console.log(myString);

Output:

1,2,3,4

Example: 2

index.js

//create an array list

myArray = ['one', 'two', 'three', 'four']

//convert array to string

myString = myArray.join()

console.log(myString);

Output:

one,two,three,four

I hope it can help you...

#Node JS