10-Aug-2022
.
Admin
Hi Friends,
I am going to explain to you an example of how to convert string to array in node js. you will learn to convert string to array in node.js. it's a simple example of string to array convert in node js. it's a simple example of how to stringto array convert in node js. Let's get started with converting string to array in node js.
There are many ways to use convert string to array in node js. I will give you examples using split(). The split() method is used to divide a string into an ordered list of two or more substrings. You can easily convert string to the array using split() in node js.
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
index.js
//create string
str1 = "nicesnippets is blog website";
//convert string to array
split_string = str1.split(" ");
console.log(split_string)
Output:
[ 'nicesnippets', 'is', 'blog', 'website' ]
I hope it can help you...
#Node JS