本文实例讲述了javascript将数组转换成csv格式的方法。分享给大家供大家参考。具体分析如下:
JavaScript中数组对象的valueOf方法可以将数组的值输出为逗号分割的字符串,下面的代码演示了如何将数组抓换成逗号和竖线分割的字符串
var fruits = ['apple', 'peaches', 'oranges', 'mangoes']; var str = fruits.valueOf(); //输出结果: apple,peaches,oranges,mangoes
如果希望使用竖线|分割
var fruits = ['apple', 'peaches', 'oranges', 'mangoes'];
var str = fruits.join("|");
//print str: apple|peaches|oranges|mangoes完整演示代码如下
Click here to convert fruits array to CSV: <button onclick="javsacript:convert()">Convert to CSV</button> <br> <pre class="brush:php;toolbar:false;">var fruits = ['apple', 'peaches', 'oranges', 'mangoes'];
希望本文所述对大家的javascript程序设计有所帮助。
java怎么学习?java怎么入门?java在哪学?java怎么学才快?不用担心,这里为大家提供了java速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号