-4

I want replace '/' by a line break in javascript.

I have this string:

L-V:DE 08:30 A 14:30 Y DE 16:30 A 20:00/S:DE 09:30 A 13:00/Festivos:SIN SERVICIO

I want to turn it into:

L-V:DE 08:30 A 14:30 Y DE 16:30 A 20:00
S:DE 09:30 A 13:00
Festivos:SIN SERVICIO
RichardMiracles
  • 2,032
  • 12
  • 28
  • 46

2 Answers2

1

you could use string.replace

replace take

  • a pattern string (you could use regex pattern)
  • a string to replace the match

example:

< "hello/i/m/here".replace(/\//g, "\n")
> "hello
i
m
here"
1

You can split it with your separator (/) and then join it using new line character (\n).

console.log('L-V:DE 08:30 A 14:30 Y DE 16:30 A 20:00/S:DE 09:30 A 13:00/Festivos:SIN SERVICIO'.split('/').join('\n'));
Jaydeep
  • 1,686
  • 1
  • 16
  • 29