I have an array full of strings like [a,b,c,d]. I want to know the efficient way of converting this into 'a|b|c|d' using Javascript.
Thanks.
Pretty simple using Array.prototype.join()
var data = ['a','b','c','d'];
console.log(data.join('|'));
You can use array.join,
var pipe_delimited_= string_array.join("|");
DEMO
var string_array = ['a','b','c','d'];
var pipe_delimited = string_array.join("|");
console.log(pipe_delimited);
Try using array's join() method.The join() method joins array elements into a string.
var arr = ['a','b','c','d'];//your aray
var string =arr.join("|");
console.log(string);
For more see here https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/join
.join()method...['a','b','c','d'].join('|')->"a|b|c|d"