保留值逗号,但删除数组中的分隔符逗号
问题描述:
希望我正确写法。保留值逗号,但删除数组中的分隔符逗号
我有一个数组:
var thisArray = ["This","That","This and That","This, That or Something Else"];
而我想做的就是这个转换成字符串,并将其转换时,取代从休息标签的所有逗号分隔符,但保留每一个值内的逗号。
现在,我的代码块:
var thisArray = ["This","That","This and That","This, That or Something Else"];
var thisString = thisArray.toString();
var thisResult = thisString.replace(",","<br/>");
return thisResult;
不过,当然,这样一来,将网着我的实际结果是:
This
That
This and That
This
That or Something Else
当我想要得到的结果是
This
That
This and That
This, That or Something Else
为了做到这一点,我需要做些什么?
答
可以使用任何作为隔板加入一个阵列:
return thisArray.join('<br />')
使用['。加入()'方法](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/join) - >'thisArray.join('
')' –
@最后一个数组替换?不去上班。 – epascarello