JavaScript

How to Convert Comma Separated String into an Array In JavaScript

Youou can simply utilize the split() method of JavaScript to split a string using a particular separator, such as comma (,), space, etc. If the separator is an empty string, it is converted to an array of characters.

The following example shows how to convert a comma-separated string into an array and retrieve each value using JavaScript.
 

How to Convert Comma Separated String into an Array In JavaScript
var languages = 'Javascript, PHP, HTML, CSS, Python';
var arr = languages.split(',');
console.log(arr);

Output :

["Javascript", " PHP", " HTML", " CSS", " Python"]
[st_adsense] mcqMCQPractice competitive and technical Multiple Choice Questions and Answers (MCQs) with simple and logical explanations to prepare for tests and interviews.Read More

Leave a Reply

Your email address will not be published. Required fields are marked *