-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"

2

4 Answers 4

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

console.log(elements.join('|'));
// expected output: one|two|three
Sign up to request clarification or add additional context in comments.

Comments

0

Try this:

let myArray = ["one", "two", "three"];
let myString = myArray.join("|");
console.log(myString);

Comments

0

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

Comments

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('|'));

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.