希望我正確寫法。保留值逗號,但刪除數組中的分隔符逗號
我有一個數組:
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
爲了做到這一點,我需要做些什麼?
使用['。加入()'方法](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/join) - >'thisArray.join('
')' –
@最後一個數組替換?不去上班。 – epascarello