For sneak peeking proposals, The full code is here:
var value = "12345XXXX98765XXXX"
for(var i = 0; i < value.length; i++) {
if(value[i] === 'X') {
value = value.replace('XXXX', ',')
}
}
value = value.substring(0, value.length - 1)
var parts = value.split(',')
console.info(parts)
If you want to know more about each part, you can read below:
I want to remove 'XXXX' and add ',' instead of 'XXXX'. How can I do that?
First of all, you need to use something called replace(), but how you want to remove all the occurrences of 'XXXX', you can do a for loop searching for any 'X' you could find.
reference: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace
var value = "12345XXXX98765XXXX"
for(var i = 0; i < value.length; i++) { //looking through the whole string
if(value[i] === 'X') { //For any X found
value = value.replace('XXXX', ',') //you should replace them for a comma
}
}
As you might have noticed, the last 'XXXX' also became a comma, so to remove it just use substring().
reference: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/substring
value = value.substring(0, value.length - 1)
So, now you have a string just like you wanted. "12345,98765"
For splitting and getting the values that are before and after the comma, you can use split() and save the result in a new variable, which is an array.
reference: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/split
var parts = value.split(',')