4

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,824
  • 17
  • 99
  • 186
Mona Coder
  • 6,212
  • 18
  • 66
  • 128

1 Answers1

12

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
  • 317,000
  • 35
  • 244
  • 286