I am having this string:
16First,Second,18Third,Fourth,25Fifth,Sixth,38Seven,Eight
I want to split the string in a way that it will produce and array containing each element after the second comma, basically
16First,Second,(split here)18Third,Fourth,(split here)25Fifth,Sixth,(split here)38Seven,Eight
So the final output would be an array like this:
Array[1] = 16First,Second,
Array[2] = 18Third,Fourth,
Array[3] = 25Fifth,Sixth,
Array[4] = 38Seven,Eight
And so on no matter how long the string is. I am confused because it needs to split on each 2nd comma and there isn’t ( or at least I haven’t find any guide/solution about it ).
>Solution :
I would use a regex match all approach here with the help of match():
var input = "16First,Second,18Third,Fourth,25Fifth,Sixth,38Seven,Eight";
var matches = input.match(/[^,]+,[^,]+/g);
console.log(matches);