10-Aug-2022
.
Admin
Hi Friends,
This tutorial is focused on node js comma separated string to array example. I explained simply about the comma-separated string to array in node.js. This post will give you a simple example of how to convert a comma-separated string to an array. In this article, we will implement a node js split comma separated string to array. follow bellow step for node.js to convert comma-separated string to an array using split().
There are many ways to use node js comma separated string to array example. I will give you examples using split() in a comma separated string to array. The split() method is used to divide a string into an ordered list of two or more substrings. You can easily convert comma separated 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 = 'JavaScript,Python,Laravel,PHP';
//convert string to array
split_string = str1.split(",");
console.log(split_string)
Output:
["JavaScript", "Python", "Laravel", "PHP"]
I hope it can help you...
#Node JS