var a = [1,[2,3],[4,5]],[6,[7,[8,9],0]]]; //定义多维数组
var s = a.toString(); //把数组转换为字符串
console.log(S); //返回字符串“1,2,3,4,5,6,7,8,9,0”
其中数组 a 是一个多维数组,JavaScript 会以迭代的方式调用 toString() 方法把所有数组都转换为字符串。
方法2:使用 join() 方法
join() 方法可以把数组转换为字符串,不过它可以指定分隔符。在调用 join() 方法时,可以传递一个参数作为分隔符来连接每个元素。如果省略参数,默认使用逗号作为分隔符,这时与 toString() 方法转换操作效果相同。var a = [1,2,3,4,5]; //定义数组
var s = a.join(""); //指定分隔符
console.log(s); //返回字符串“12345”
更多编程相关知识,请访问:编程视频!!
Current, I am reading a file, ...
数组:Array([0] => Array([productid] => 2[cateid] => 4[title] => 衣[descr] => 吖吖吖吖吖吖吖吖吖吖吖吖吖吖吖吖吖吖吖吖吖[num] => 197[price] => 888.00[cover] => 7xpizy....
I'm developing aPHP app and I have a problem by converting a string array into an object array. I tried to force casting my string into an array by using (array), but it won't works. Here is my ...
I want to get the count of each variable in an array. Am getting the object like [1,1,2,2,3,4,5,4,6]$array = array(12,43,66,21,56,43,43,78,78,100,43,43,43,21); ...