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 Answers
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('|'));
.join()as a template tag, e.g.elements.join`|`