js把数组转换为以逗号分隔的字符串

var filePath=['1.jpg','2.png','3.png','4.jpg']
var newArr = arr.splice($.inArray(filePath, arr, 1));
var dotStr=newArr.join(',');

最后会得到字符串:“1.jpg,2,png,3,png,4,jpg”

 

var aaa=[1,2,4,5,6];
console.log(aaa.join(","))
输出
1,2,4,5,6
var aaa=["a","b","c","d"]
console.log(aaa.join(","))
输出
a,b,c,d

下面的代码是错误的,不支持

var aaa=[{a:1,b:2},{a:2,b:3}]
console.log(aaa.join(","))
输出
[object Object],[object Object]
posted @ 2021-08-17 09:34  James·wang  阅读(10462)  评论(0编辑  收藏  举报