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

2 Answers 2

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"
Sign up to request clarification or add additional context in comments.

Comments

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

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.