Reputation: 121
I wanted to know if there was a function that could turn an array into a string separated with Quotation Marks and commas in JS?
var array = [1,2,3]
var result = '["1", "2", "3"]';
Upvotes: 2
Views: 500
Reputation: 28414
You can use .map
to convert array elements to strings, and JSON.stringify
to get the resulting string:
const array = [1,2,3];
const result = JSON.stringify(array.map(String));
console.log(result);
Upvotes: 6