如何将数组转换为字符串并通过管道分隔值

时间:2018-05-05 04:51:05

标签: javascript ecmascript-6

我如何将数组转换为字符串并在javascript(es6)中通过管道分隔值?例如,["one", "two", "three"]应转换为"one|two|three"

4 个答案:

答案 0 :(得分:1)

var elements = ["one", "two", "three"];

console.log(elements.join('|'));
// expected output: one|two|three

答案 1 :(得分:0)

试试这个:

proxy.exe

答案 2 :(得分:0)



var elements = ["one", "two", "three"];
var pipe_delimited_string = elements.join("|");
console.log(pipe_delimited_string);




答案 3 :(得分:0)

Join函数用于将数组转换为字符串,split('')函数用于将字符串转换为数组,即



var arrayData = ['data 1', 'data 2', 'data 3'];


console.log(arrayData.join('|'));//bydefault it split with ','

var astringyData = 'data 1|data 2|data 3';

console.log(astringyData.split('|'));