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"]';
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);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.