-5

I have data like

var result = 'Zika NAA, Blood|Zika NAA, Urine' 

My requirement is

var result = Zika NAA, Blood
             Zika NAA, Urine

| symbol shouldn't be there. How to achieve in javascript ?

Soumya Behera
  • 2,325
  • 4
  • 15
  • 25

2 Answers2

1

var result = 'Zika NAA, Blood|Zika NAA, Urine'.replace('|', ' ');
console.log(result);
Maxim Kuzmin
  • 2,574
  • 19
  • 24
  • This will not split the data - merely space it further apart - @Alexander Elgin has the correct answer IMO – gavgrif Aug 01 '17 at 10:04
  • Zika NAA, Urine sud be in new line. – Soumya Behera Aug 01 '17 at 10:04
  • Being on a newline in the js is not required - its only better for readability - not functionality - the reason why I up-voted and praised @Alexander Elgin is that his answer splits the one string into an array that has two items - this can be iterated over and appended to a ul or a table or however you are rendering it in the DOM (or if it was passed to a variable and then iterated over (instead of just console logging the items) it would.) This answer cannot do that without itself being split at the newly introduced space. – gavgrif Aug 01 '17 at 10:06
1

document.write('Zika NAA, Blood|Zika NAA, Urine'.split('|').join('<br>'));
Alexander Elgin
  • 6,796
  • 4
  • 40
  • 50