Reputation: 179
How to remove all the characters until you encounter second comma(,) in the sentence in js?
I have something like this in my string:
var str = "hello,abc,def,jkl,mno,pqr,stu";
I want the string to contain something like this:
str = "def,jkl,mno,pqr,stu"
How to do something like this?
Is there way to do this other than putting in loop checking for comma then erasing?
Upvotes: 0
Views: 51
Reputation: 1194
split
.slice
join
.var str = "hello,abc,def,jkl,mno,pqr,stu";
var arr = str.split(',');
var newStr = arr.slice(2, arr.length).join(',')
console.log(newStr)
Upvotes: 1