0

I have a string like below

var str = "Lorem Ipsum is simply& dummy text of the &printing and & typesetting industry."

How can I remove the second character & and everything after it in jQuery?

halfer
  • 19,471
  • 17
  • 87
  • 173
Mona Coder
  • 5,994
  • 17
  • 60
  • 118

1 Answers1

6

You can combine split and join:

str.split("&", 2).join("&")

The argument 2 will make that split only returns the first two substrings that are split off, the rest is ignored. join would put those 2 pieces back together with the restored &.

trincot
  • 263,463
  • 30
  • 215
  • 251