-1

How could i convert array into string and separate values by pipe in javascript (es6)? For example, ["one", "two", "three"] should be converted into "one|two|three"

4 Answers4

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

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

Try this:

let myArray = ["one", "two", "three"];
let myString = myArray.join("|");
console.log(myString);
Abe
  • 1,357
  • 13
  • 31
0

var elements = ["one", "two", "three"];
var pipe_delimited_string = elements.join("|");
console.log(pipe_delimited_string);
dayan khan
  • 51
  • 3
0

The Join function is used to convert array to string and split('') function is used to convert string into array i.e

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('|'));
Faraz Babakhel
  • 654
  • 5
  • 14