Remove text before first comma

  • A+
Category:Languages

I have the following text:

Kenya, Garden, PFO, Inv 2123, DG, Lot 5543, Ra 

And I only want to show the text after the first ,

Result:

Garden, PFO, Inv 2123, DG, Lot 5543, Ra 

How can I do this with Javascript?

 


Split string by , delimiter and remove first item of array using Array.slice() and then join array.

var str = "Kenya, Garden, PFO, Inv 2123, DG, Lot 5543, Ra"; var newStr = str.split(", ").slice(1).join(", "); console.log(newStr);

Also you can find index of first , and get all string after it using String.slice().

var str = "Kenya, Garden, PFO, Inv 2123, DG, Lot 5543, Ra"; var newStr = str.slice(str.indexOf(',')+1).trim(); console.log(newStr);

Comment

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: