删除数组分隔符 [英] Remove array delimiters
本文介绍了删除数组分隔符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否有可能在array.toString时删除分隔符? (javascript)
Is it possible remove delimiters when you array.toString? (javascript)
var myArray = [ 'zero', 'one', 'two', 'three', 'four', 'five' ];
var result = myArray .toString();
结果应该是zeroonetwothreefourfive
result shoud be "zeroonetwothreefourfive"
推荐答案
您可以使用 join
而不是 toString
-
You could use join
instead of toString
-
var myArray = [ 'zero', 'one', 'two', 'three', 'four', 'five' ];
var result = myArray.join('');
join
将加入所有元素使用传递给 join
函数的参数作为分隔符将数组转换为字符串。因此,调用 join
并传入一个空字符串应该完全符合您的要求。
join
will join all the elements of the array into a string using the argument passed to the join
function as a delimiter. So calling join
and passing in an empty string should do exactly what you require.
演示 - http://jsfiddle.net/jAEVY/
这篇关于删除数组分隔符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文